implementation of IDisposable : IDisposable « Class « C# / CSharp Tutorial






using System;

class MyClass: IDisposable
{
     private bool Disposed = false;

     public void Dispose()
     {
           Dispose(true);
           GC.SuppressFinalize(this);
          

     }
     private void Dispose(bool disposing)
     {
           if(!this.Disposed)
           {
                  if(disposing)
                  {
                       //free any managed resources
                  }

                  //free unmanaged resources
           }
           
           Disposed = true;
     }
     ~MyClass()
     {
           Dispose(false);
     }
}








7.54.IDisposable
7.54.1.Simple IDisposable pattern
7.54.2.implementation of IDisposable
7.54.3.Complex IDisposable pattern