Use of Finalize/Dispose method in C#

后端 未结 13 2050
轮回少年
轮回少年 2020-11-21 23:20

C# 2008

I have been working on this for a while now, and I am still confused about the use of finalize and dispose methods in code. My questions are below:

相关标签:
13条回答
  • 2020-11-21 23:51

    From what I know, it's highly recommended NOT to use the Finalizer / Destructor:

    public ~MyClass() {
      //dont use this
    }
    

    Mostly, this is due to not knowing when or IF it will be called. The dispose method is much better, especially if you us using or dispose directly.

    using is good. use it :)

    0 讨论(0)
提交回复
热议问题