close or dispose

前端 未结 6 1474
春和景丽
春和景丽 2020-12-03 09:44

StreamReader class has both close and dispose method. I want to know which method to call to clean up all resources.

If making use of using block, I think it will c

6条回答
  •  星月不相逢
    2020-12-03 10:16

    There appears to be some concern about whether Dispose actually does its job properly.

    Essentially - you can be fairly certain that anything in the BCL(Base Class Library) which implements IDisposable will tidy itself up properly when dispose is called - such as when a using statement goes out of scope.

    If there were issues with streams not being closed they would have been picked up by now - you can trust IDisposable. It's when you're using other libraries that you rely on the Dispose implementation.

提交回复
热议问题