Object dispose in IDisposable class

You have to implement IDisposable interface methods:

 public void Dispose()
    {
        // Clear all unmanaged resources
    }

Whenever you then instantiate your object you should do it inside a using statement

using(Program3 p3 = new Program3())
{
//do your job
} // here the p3.Dispose gets called

It is important to note that the point of Dispose is to free unmanaged resources. What you get in. Net is already managed, so only if you are implementing something of your own should you use IDisposable.

Browse More Popular Posts

Leave a Comment