关于IDisposable [英] About IDisposable

查看:107
本文介绍了关于IDisposable的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好.. :)
我想问你有关IDisposable的问题.如果我们要实现IDisposable接口时我的类没有构造函数怎么办?有什么问题吗 ?你能解释一下我吗? :)谢谢

Hi all.. :)
I wanna ask you about IDisposable. What if my class doesn''t have constructor when we want to implement IDisposable interface ? Is there any problem ? May you explain me ?? :) Thanks

推荐答案

如果您未明确包含构造函数,则C#将自动提供不带参数的默认构造函数. (请参见使用构造函数 [
If you don''t explicitly include a constructor C# will automatically provide a default constructor that takes no arguments. (See Using Constructors[^])

There is no problem implementing IDisposable on a class that contains only the default constructor.

It is also possible to explicitly define the default constructor and mark it as private (preventing instantiation from outside of the class itself). Even in this case it is still perfectly OK to implement the IDisposable interface, but you will have to be aware of where you are instantiating your class from and who is responsible for calling Dispose(). You may find you have to call it manually rather than using the usual ''using'' statement.


我相信以下几个链接将为您显示正确的路径

http://msdn.microsoft.com/en-us/library/system.idisposable.aspx [^ ]

http://msdn.microsoft.com/en-us/library/b1yfkh5e (v = VS.100).aspx [
I believe the following few links will show you the right path

http://msdn.microsoft.com/en-us/library/system.idisposable.aspx[^]

http://msdn.microsoft.com/en-us/library/b1yfkh5e(v=VS.100).aspx[^]

Besides this if you want to know something more please let me know


这篇关于关于IDisposable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆