close or dispose

前端 未结 6 1467
春和景丽
春和景丽 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:24

    Use Dispose via a using block to guarantee that clean-up happens.

    Use Close if you finish with the object considerably before the end of the using block, to be as prompt as possible in releasing any resources.

    The two will hence work hand-in-hand, though the latter can be redundant if you are going to reach the end of the block in a few nanoseconds anyway.

提交回复
热议问题