如果该类没有Dispose方法,该类如何实现IDISPOSABLE?
-
30-09-2019 - |
题
ftpwebresponse 实现Idisposable,但没有处理方法。怎么可能?
解决方案
它确实通过继承具有处置方法,但这是一个明确的实现。要称呼它,您必须使用
((IDisposable)myObject).Dispose();
或者,当然,只需将其包裹在一个 using
块,就像您对您的明确电话一样。
其他提示
它在基类Webresponse中实现,请参阅 http://msdn.microsoft.com/en-us/library/system.net.webresponse_methods.aspx
当您实现 interface
明确地,您不会在列表中获得该方法。您将必须将该对象施加到实施 interface
访问该方法。
public class MyClass : IDisposable
{
void IDisposable.Dispose()
{
throw new NotImplementedException();
}
}
它是在基类Webresponse中实现的
void IDisposable.Dispose()
{
try
{
this.Close();
this.OnDispose();
}
catch
{
}
}
Alt Text http://img227.imageshack.us/img227/2428/redgatesnetreflector.png
它继承 system.net.Webresponse 实现这些方法。
不隶属于 StackOverflow