Is there any benefit to implementing IDisposable on classes which do not have resources?

后端 未结 11 2082
挽巷
挽巷 2020-12-14 05:14

In C#, if a class, such as a manager class, does not have resources, is there any benefit to having it : IDisposable?

Simple example:

pu         


        
11条回答
  •  一生所求
    2020-12-14 06:05

    No, if there are no (managed or unmanaged) resources there is no need for IDisposable either.

    Small caveat: some people use IDisposable to clean up eventhandlers or large memory buffers but

    • you don't seem to use those
    • it's a questionable pattern anyway.

提交回复
热议问题