问题描述
我一直在学习AsyncOperation类,并且遇到了这个
代码(抱歉我几天前得到它,不记得具体的链接)。
无论如何,我想知道12号线上的波浪号(〜)是什么或它意味着什么。
我已经使用了C#一段时间了,不知何故没有遇到了代字号
了。
谢谢。
1.命名空间System.ComponentModel
2. {
3.公共密封类AsyncOperation
4. {
5.内部AsyncOperation(SynchronizationContext ctx,对象状态)
6. {
7. this.ctx = ctx;
8. this.state = state;
9. ctx.OperationStarted();
10.}
11.
12.~AsyncOperation()
13. {
14. if(!done&& ctx!= null)
15. ctx.OperationCompleted();
16.}
//保持g代码省略
---------------结束OP ----------------- -----
I have been learning about the AsyncOperation class and came across this
code (sorry I got it a few days ago and don''t remember the specific link).
Anyway, I am wondering what the tilde (~) on line 12 does or what it means.
I''ve been using C# for a while and somehow haven''t encountered the tilde
yet.
Thanks.
1. namespace System.ComponentModel
2. {
3. public sealed class AsyncOperation
4. {
5. internal AsyncOperation (SynchronizationContext ctx, object state)
6. {
7. this.ctx = ctx;
8. this.state = state;
9. ctx.OperationStarted ();
10. }
11.
12. ~AsyncOperation ()
13. {
14. if (!done && ctx != null)
15. ctx.OperationCompleted ();
16. }
//remaining code omitted
--------------- END OF OP ----------------------
推荐答案
它意味着析构函数(与C ++相同)。
It means destructor (the same as C++).
不,它没有。
它声明_finalizer_与C ++不完全相同
析构函数。
No, it doesn''t.
It declares the _finalizer_ which is not exactly the same as a C++
destructor.
这是定义终结器方法的语法。它编译为覆盖Object.Finalize()的方法
。语法与C ++中的
析构函数相同。
Mattias
-
Mattias Sj?gren [C#MVP] mattias @ mvps.org
|
请回复到新闻组。
It''s the syntax to define a finalizer method. It compiles to a method
that overrides Object.Finalize(). The syntax is the same as for
destructors in C++.
Mattias
--
Mattias Sj?gren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
这篇关于语法问题 - 代字号(〜)的含义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!