Simple Finalize : destructor « Class « C# / CSharp Tutorial






using System;

class MyClass
{
  ~MyClass()
  {
    Console.WriteLine("Finalizing");
  }
}

class MainClass
{
  static void Main(string[] args)
  {
    MyClass fc = new MyClass();
    Console.WriteLine("Exiting main");
  }
}
Exiting main
Finalizing








7.14.destructor
7.14.1.Destructors
7.14.2.Simple Finalize
7.14.3.Illustrates a destructor
7.14.4.Demonstrate a destructor.
7.14.5.Use destructor and implement IDisposable
7.14.6.Base destructor
7.14.7.Update static field in the deconstructor