Illustrates a destructor : Destructor « Class Interface « C# / C Sharp






Illustrates a destructor

Illustrates a destructor
/*
Mastering Visual C# .NET
by Jason Price, Mike Gunderloy

Publisher: Sybex;
ISBN: 0782129110
*/
/*
  Example5_14.cs illustrates a destructor
*/


// declare the Car class
class Car
{

  // define the destructor
  ~Car()
  {
    System.Console.WriteLine("In ~Car() destructor");
    // do any cleaning up here
  }

}


public class Example5_14
{

  public static void Main()
  {

    // create a Car object
    Car myCar = new Car();

    System.Console.WriteLine("At the end of Main()");

  }

}


           
       








Related examples in the same category

1.Finalizable Disposable Class
2.force the GC to invoke Finalize() for finalizable objects created in this AppDomain.
3.the destructors are called bottom-up, which confirms the sequencing of destructors.
4.Shows that stack unwinding in C# does not necessarily call destructorsShows that stack unwinding in C# does not necessarily call destructors
5.Demonstrate a destructorDemonstrate a destructor