如果没有Dispose方法,该类如何实现IDisposable? [英] How does this class implement IDisposable if it doesn't have a Dispose method?

查看:190
本文介绍了如果没有Dispose方法,该类如何实现IDisposable?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

FtpWebResponse 实现IDisposable,但它没有Dispose方法。这怎么可能?

FtpWebResponse implements IDisposable, but it doesn't have a Dispose method. How is that possible?

推荐答案

它通过继承确实有Dispose方法,但它是一个显式实现。要调用它,你必须使用

It does have the Dispose method through inheritance, but it is an explicit implementation. To call it, you would have to use

((IDisposable)myObject).Dispose();

当然,只需使用中$ c>阻止,因为它显式调用你。

Or, of course, just wrap it in a using block, as it does the explicit call for you.

这篇关于如果没有Dispose方法,该类如何实现IDisposable?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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