8.7.9 Destructors

来源:互联网 发布:马拉多纳 知乎 编辑:程序博客网 时间:2024/05/19 13:06
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.
C# LANGUAGE SPECIFICATION
40
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.
原创粉丝点击