Export (0) Print
Expand All

1.7.9 Destructors

Visual Studio .NET 2003

A destructor is a member that implements the actions required to destruct an instance of a class. Destructors cannot have parameters, they cannot have accessibility modifiers, and they cannot be called explicitly. The destructor for an instance is called automatically during garbage collection.

The example

using System;
class Point
   public double x, y;
   public Point(double x, double y) {
      this.x = x;
      this.y = y;
   ~Point() {
      Console.WriteLine("Destructed {0}", this);
   public override string ToString() {
      return string.Format("({0}, {1})", x, y);

shows a Point class with a destructor.

© 2014 Microsoft