析构函数用于析构类的实例。

  • 不能在结构中定义析构函数。只能对类使用析构函数。
  • 一个类只能有一个析构函数。
  • 无法继承或重载析构函数。
  • 无法调用析构函数。它们是被自动调用的。
  • 析构函数既没有修饰符,也没有参数。

Car 的析构函数的声明:

View Code
class Car
{
    ~Car()  // destructor
    {
        // cleanup statements...
    }
}

这样,前面的析构函数代码被隐式地转换为以下代码:

View Code
protected override void Finalize()
{
    try
    {
        // Cleanup statements...
    }
    finally
    {
        base.Finalize();
    }
}

Finalize 方法(从派生程度最大的到派生程度最小的)。 

相关文章:

  • 2021-11-01
  • 2021-05-18
  • 2021-05-19
  • 2021-12-14
  • 2022-12-23
  • 2021-12-17
  • 2022-12-23
  • 2021-08-30
猜你喜欢
  • 2021-08-24
  • 2022-12-23
  • 2021-08-16
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-09
相关资源
相似解决方案