Destructors

Destructors are used by the .NET Framework to clean up after objects. In general, you don ’ t have to provide code for a destructor method; instead, the default operation does the work for you. However, you can provide specific instructions if anything important needs to be done before the object instance is deleted.
 
When a variable goes out of scope, for example, it may not be accessible from your code, but it may still exist somewhere in your computer ’ s memory. Only when the .NET runtime performs its garbage collection cleanup is the instance completely destroyed.
 
Don ’ t rely on the destructor to free up resources used by an object instance, as this may occur long after the object is of no further use to you. If the resources in use are critical, then this can cause problems. A Destructor is demonstrated as :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace ConsoleApplication1
{

    public class baseClass
    {
        public baseClass()
        {
            Console.WriteLine("baseClass Constructor");
        }
        ~baseClass() // defining desctuctors
        {
            Console.WriteLine("Destructor executes after pressing key");
        }
    }
    class Program
    {
        Program()
        {
            Console.WriteLine("inside main program class");
        }
        static void Main(string[] args)
        {
            baseClass a = new baseClass();
            Program pr = new Program();
            new Program(); // another way to call constructors
            Console.Read();
        }
    }
}