IDisposable, does it really matter

后端 未结 9 2996
予麋鹿
予麋鹿 2021-02-20 09:19

Coming from C/C++ a long time ago I still have a habit of ensuring that all resources are cleaned up correctly. I always ensure Dispose is called on IDisposable classes and impl

9条回答
  •  失恋的感觉
    2021-02-20 09:44

    Besides the obvious cases (already mentioned) of resources running out, another benefit of IDisposable is that, since it guarantees that Dispose() is called when a using block exits, you can use it for all kinds of things, even things that aren't just "perform operation with OS resource".

    In this way, it's like a poor-man's substitute for Ruby blocks, or for one small use case of Lisp macros.

提交回复
热议问题