ftpwebresponse 实现Idisposable,但没有处理方法。怎么可能?

有帮助吗?

解决方案

它确实通过继承具有处置方法,但这是一个明确的实现。要称呼它,您必须使用

((IDisposable)myObject).Dispose();

或者,当然,只需将其包裹在一个 using 块,就像您对您的明确电话一样。

其他提示

当您实现 interface 明确地,您不会在列表中获得该方法。您将必须将该对象施加到实施 interface 访问该方法。

public class MyClass : IDisposable
{
    void IDisposable.Dispose()
    {
        throw new NotImplementedException();
    }
}

参考 : http://msdn.microsoft.com/en-us/library/ms173157.aspx

它是在基类Webresponse中实现的

void IDisposable.Dispose()
{
try
{
    this.Close();
    this.OnDispose();
}
catch
{
}
}

Alt Text http://img227.imageshack.us/img227/2428/redgatesnetreflector.png

它继承 system.net.Webresponse 实现这些方法。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top