舉例如下
class Demo {
~Demo() {
System.Console.WriteLine("The destructor is called.");
}
static void Main() {
Demo d = new Demo();
}
}
/* 《程式語言教學誌》的範例程式
http://pydoing.blogspot.com/
檔名:class05.cs
功能:示範 C# 程式
作者:張凱慶
時間:西元 2013 年 6 月 */解構子的定義是在建構子 (constructor) 前面加上 ~ 符號
~Demo() {
System.Console.WriteLine("The destructor is called.");
}編譯執行,結果如下

| 中英文術語對照 | |
|---|---|
| 解構子 | destructor |
| 物件 | object |
| 方法 | method |
| 建構子 | constructor |
您可以繼續參考
類別
相關目錄
回 C# 快速導覽
回 C# 教材
回首頁
參考資料
Standard ECMA-334 C# Language Specification
msdn: 解構函式 (C# 程式設計手冊)
沒有留言:
張貼留言