Using the Destructor/Dispose of the base class?

Tipx picture Tipx · Apr 20, 2011 · Viewed 9.1k times · Source

In C#, as mentioned in the Documentation, and this nice post's accepted answer, it's stated that classes don't inherit the Destructor of their parent class.

The question : If I want to make sure to dispose the private elements of the base class, is the proper way to implement IDisposable in all the child class, and in the Dispose method, call base.Dispose()?

It looks alright to do so, but I would have preferred a way which wouldn't require implementation in all of the child classes.

Answer

Nik picture Nik · Apr 20, 2011

MSDN states that destructors are called on base classes automatically.