Why would a class implement IDisposable explicitly instead of implicitly?

后端 未结 4 2101
伪装坚强ぢ
伪装坚强ぢ 2020-12-01 23:57

I was using the FtpWebResponse class and didn\'t see a Dispose method. It turns out that the class implements IDisposable, but does so explicitly so that you must first cas

4条回答
  •  春和景丽
    2020-12-02 00:13

    It's a little weird looking to me too. For what it's worth: the base class (WebResponse) implements a Close() method. Reflector shows that WebResponse's Dispose() method just calls Close() and an Internal OnDispose virtual that does nothing.

    I have to confess that it smells a little to me, but I bet that they explicitly implemented IDisposable so that there would not be confusion in Intellisense between calling Close() or Dispose().

提交回复
热议问题