Complex IDisposable pattern : IDisposable : Class C# Examples


C# Examples » Class » IDisposable »

 

Complex IDisposable pattern









    
using  System;
using  System.Collections.Generic;
using  System.Globalization;
using  System.IO;
using  System.Text;
using  System.Security.Cryptography;

class  MyClass  :  IDisposable
{
        private  IntPtr  myHandle  =  IntPtr.Zero;
        ~MyClass()
        {
                Dispose(false);
        }
        public  void  Dispose()
        {
                Dispose(true);
                GC.SuppressFinalize(this);
        }
        protected  void  Dispose(bool  disposing)
        {
                IntPtr  h  =  myHandle;
                if  (h  !=  IntPtr.Zero)
                {
                        h  =  IntPtr.Zero;
                }
        }
}

public  class  MainClass
{
        public  static  void  Main()
        {
                using  (MyClass  mc  =  new  MyClass())
                {
                }
        }

}
    
   
  
   




HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Class
» IDisposable