[英]If I have a Dispose method, must I implement IDisposable?
I have a class that contains a Dispose
method. 我有一个包含Dispose
方法的类。 In this method I abort a thread. 在这个方法中,我中止了一个线程。 Is it necessary to implement the IDisposable
interface? 是否有必要实现IDisposable
接口?
If you implement IDisposable
interface then your class object could be used in using block that automatically call the Dispose
method implicitly. 如果您实现了IDisposable
接口,那么您的类对象可以用于使用隐式自动调用Dispose
方法的块。
From the answer from JaredPar 来自JaredPar的答案
There are only 2 reasons for implementing IDisposable on a type 在类型上实现IDisposable只有两个原因
Is there any benefit to implementing IDisposable on classes which do not have resources? 在没有资源的类上实现IDisposable有什么好处吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.