What's the point of overriding Dispose(bool disposing) in .NET?

后端 未结 8 1018
故里飘歌
故里飘歌 2021-01-30 10:38

If I write a class in C# that implements IDisposable, why isn\'t is sufficient for me to simply implement

public void Dispose(){ ... } 

to han

8条回答
  •  一个人的身影
    2021-01-30 11:27

    It's not strictly necessary. It is part of the recommended Disposable pattern. If you haven't read the Framework Design Guidelines section on this (9.3 in the first edition, don't have the second edition handy sorry) then you should. Try this link.

    It's useful for distinguishing between disposable cleanup and finalizable garbage-collection-is-trashing-me.

    You don't have to do it that way but you should read up on it and understand why this is recommended before discounting it as unnecessary.

提交回复
热议问题