Destructors in C#

We have seen that constructors allow you to specify actions that must take place whenever an instance of a class is created. Conversely, destructors are called before an object is destroyed by the garbage collector. Given this behavior, a destructor would initially seem like a great place to put code to free unmanaged resources and perform a general cleanup. Unfortunately, things are not so straightforward.


Syntax for a destructor:

   class MyClass
   {      
        ~mMyClass()
        {
            //implemention
        }
      
    }




No comments:

Post a Comment