`
talin2010
  • 浏览: 502085 次
  • 性别: Icon_minigender_1
  • 来自: 河北
社区版块
存档分类
最新评论

17.12 Destructors

F# 
阅读更多
A destructor is a member that implements the actions required to destruct an
instance of a class. A destructor is
declared using a destructor-declaration:
destructor-declaration:
attributesopt externopt ~ identifier ( ) destructor-body
destructor-body:
block
;
A destructor-declaration may include a set of attributes (§24).
The identifier of a destructor-declarator must name the class in which the
destructor is declared. If any other
name is specified, a compile-time error occurs.
When a destructor declaration includes an extern modifier, the destructor
is said to be an external destructor.
Because an external destructor declaration provides no actual
implementation, its destructor-body consists of a
semicolon. For all other destructors, the destructor-body consists of a
block, which specifies the statements to
execute in order to destruct an instance of the class. A destructor-body
corresponds exactly to the method-body of
an instance method with a void return type (§17.5.8).
Destructors are not inherited. Thus, a class has no destructors other than
the one which may be declared in that
class.
[Note: Since a destructor is required to have no parameters, it cannot be
overloaded, so a class can have, at most,
one destructor. end note]
Destructors are invoked automatically, and cannot be invoked explicitly. An
instance becomes eligible for
destruction when it is no longer possible for any code to use that
instance. Execution of the destructor for the
instance may occur at any time after the instance becomes eligible for
destruction. When an instance is
destructed, the destructors in that instance?s inheritance chain are
called, in order, from most derived to least
derived [Example: The output of the example
Chapter 17 Classes
265
using System;
class A
{
~A() {
Console.WriteLine("A’s destructor");
}
}
class B: A
{
~B() {
Console.WriteLine("B’s destructor");
}
}
class Test
{
static void Main() {
B b = new B();
b = null;
GC.Collect();
GC.WaitForPendingFinalizers();
}
}
is
B?s destructor
A?s destructor
since destructors in an inheritance chain are called in order, from most
derived to least derived. The GC.Collect
method is not required, but may be provided by an implementation. end
example]
Destructors may be implemented by overriding the virtual method Finalize on
System.Object. In any event,
C# programs are not permitted to override this method or call it (or
overrides of it) directly. [Example: For
instance, the program
class A
{
override protected void Finalize() {} // error
public void F() {
this.Finalize(); // error
}
}
contains two errors. end example]
The compiler behaves as if this method, and overrides of it, does not exist
at all. [Example: Thus, this program:
class A
{
void Finalize() {} // permitted
}
is valid and the method shown hides System.Object?s Finalize method. end
example]
For a discussion of the behavior when an exception is thrown from a
destructor, see §23.3.
分享到:
评论

相关推荐

    codeblocks-17.12mingw

    codeblocks-17.12mingw codeblocks-17.12mingw codeblocks-17.12mingw 最新的带编译器!

    Halcon17.12完全破解

    Halcon17完全破解,适用版本17.12.0.0和17.12.0.1,亲测两个版本都可以。只需将解压文件放到X:\Program Files\MVTec\HALCON-17.12-Progress\bin\x64-win64替换即可使用。

    【汉化版】CodeBlocks17.12

    本人亲自手动汉化的 Code::Blocks 17.12 正式版汉化包。 1.延续了上一版本16.01汉化包,所以本汉化包同样能使用在16.01版本上。 2.该汉化包将编译器配置的汉化单独抽取出来汉化,避免上一版本汉化包汉化后不能修改...

    Code::Blocks17.12

    Code::Blocks17.12下载文件,免费开源C/C++开发工具。

    eric6-17.12.zip

    eric6-17.12.zip

    HALCON 17.12.0.0 x64 x86 破解

    HALCON 17.12.0.0 破解, 特可有用的。X86, x64 

    codeblocks 17.12 汉化包

    codeblocks 17.12 汉化包,该汉化包网上发布时间最早在2018/2/17,资源来源于网上,本人亲自自用OK,现分享出来

    halcon17.12.rar

    halcon免费的17.12版本,软件安装完成后替换对应目录中的dll文件即可使用。 注意安装版本x64还是X86

    CodeBlocks 17.12 汉化补丁-v5.2.6

    本人亲自手动汉化的 Code::Blocks 17.12 正式版汉化包。 1.延续了上一版本16.01汉化包,所以本汉化包同样能使用在16.01版本上。 2.该汉化包将编译器配置的汉化单独抽取出来汉化,避免上一版本汉化包汉化后不能修改...

    eric6 17.12 中文包

    官方不支持中文包了,好像最新的就是17.12版本了,不过,可以用

    halcon17.12破解补丁-实测可用

    halcon17.12破解补丁,直接替换halcon.exe文件夹目录下即可,实测可用

    CODEBLOCKS 17.12汉化包

    CODEBLOCKS 是我个人很喜欢的一个IDE,它轻巧,强大,跨平台,而且新版本更新加入了对Qt5的支持!以上是CODEBLOCKS 17.12汉化包

    HALCON17.12Progress12月License完整特别版(附破解方法)3264位

    近日MVTec公司正式发布全新版本HALCON Progress 17.12。HALCON Progress与以往HALCON不同,是MVTec定义的一个全新机器视觉软件产品。HALCON Progress是用户享有最新机器视觉功能的一条快速途径。HALCON Progress大约...

    Aspose.Words17.12破解版

    Aspose.Words17.12破解版 无水印 引用就可以使用 支持word转PDF、等

    codeblocks17.12安装包及+汉化补丁+视频教程

    codeblocks17.12安装包及+汉化补丁+视频教程,自带编译器.\无须配置.

    codeblock17.12+汉化包

    codeblock17.12+汉化包 ,TDM-GCC-64,完整安装后,将locale下的文件拷贝到share/codeblock/下

Global site tag (gtag.js) - Google Analytics