必须要有 Dispose 方法才能使用 using 吗?

作者:vkvi 来源:ITPOW(原创) 日期:2020-2-7

如上代码,writer 有 Dispose() 方法,这个 Dispose() 方法是从 TextWriter 重写的,而 TextWriter 是对接口 IDisposable 的实现,所以能用 using。

再看下面的代码:

上面代码也能用 using,在 BinaryReader 上按 F12 也发现它确实是从 IDisposable 实现的,可是就是没有实现 Dispose() 方法,这就奇怪了,不是接口必须 public 实现全部方法吗。

相关文章