语法问题 - 代字号(〜)的含义 [英] Syntax Question - meaning of tilde (~)

查看:66
本文介绍了语法问题 - 代字号(〜)的含义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在学习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 ++相同)。


WJ


" Frankie"写道:
It means destructor (the same as C++).

WJ

"Frankie" wrote:

我一直在学习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.OperationComp leted();

16.}

//剩余代码省略


---------- -----结束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 ----------------------


WJ写道:
WJ wrote:

[...]
[...]

>无论如何,我想知道什么是波浪号( 〜)第12行做了什么或意味着什么。
我已经使用了C#一段时间了,不知怎么没有遇到代字号
>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



它意味着析构函数(与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.



>无论如何,我想知道什么是波浪号(〜)第12行做了什么或意味着什么。
我已经使用了C#一段时间了,不知怎的还没有遇到代字号

>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.



这是定义终结器方法的语法。它编译为覆盖Object.Finalize()的方法

。语法与C ++中的

析构函数相同。

Mattias


-

Mattias Sj?gren [C#MVP] mattias @ mvps.org
http:// www.msjogren.net/dotnet/ | http://www.dotnetinterop.com

请回复到新闻组。

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.


这篇关于语法问题 - 代字号(〜)的含义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆