473,439 Members | 1,955 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,439 software developers and data experts.

Syntax Question - meaning of tilde (~)

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 ----------------------
Sep 14 '07 #1
11 11192
It means destructor (the same as C++).

WJ

"Frankie" wrote:
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 ----------------------
Sep 14 '07 #2
WJ wrote:
[...]
>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

It means destructor (the same as C++).
No, it doesn't.

It declares the _finalizer_ which is not exactly the same as a C++
destructor.
Sep 14 '07 #3
>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.
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.
Sep 14 '07 #4
It's default destructor of this class,
yes, C# also has something which is called destructors.
You can TRY to use this feature, by typing Object.Finalize();

On Sep 14, 11:16 pm, "Frankie" <A...@B.COMwrote:
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 ----------------------

Sep 14 '07 #5
Peter Duniho wrote:
WJ wrote:
>>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

It means destructor (the same as C++).

No, it doesn't.

It declares the _finalizer_ which is not exactly the same as a C++
destructor.
In the two first edition of the C# standard it was named destructor.

In the third edition they renamed it to finalizer.

To my best knowledge they did not change any semantics.

Arne
Sep 15 '07 #6
"Arne Vajhøj" <ar**@vajhoej.dkwrote in message
news:46***********************@news.sunsite.dk...
Peter Duniho wrote:
>WJ wrote:
>>>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

It means destructor (the same as C++).

No, it doesn't.

It declares the _finalizer_ which is not exactly the same as a C++
destructor.

In the two first edition of the C# standard it was named destructor.

In the third edition they renamed it to finalizer.

To my best knowledge they did not change any semantics.
In C#

To call it "the same" as a C++ destructor is not entirely correct, though.
Finalization can be waaaaay different than C++ destruction. <g>

--
Doug Semler, MCPD
a.a. #705, BAAWA. EAC Guardian of the Horn of the IPU (pbuhh).
The answer is 42; DNRC o-
Gur Hfrarg unf orpbzr fb shyy bs penc gurfr qnlf, abbar rira
erpbtavmrf fvzcyr guvatf yvxr ebg13 nalzber. Fnq, vfa'g vg?

Sep 15 '07 #7
Doug Semler wrote:
"Arne Vajhøj" <ar**@vajhoej.dkwrote in message
news:46***********************@news.sunsite.dk...
>Peter Duniho wrote:
>>WJ wrote:
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

It means destructor (the same as C++).

No, it doesn't.

It declares the _finalizer_ which is not exactly the same as a C++
destructor.

In the two first edition of the C# standard it was named destructor.

In the third edition they renamed it to finalizer.

To my best knowledge they did not change any semantics.

In C#

To call it "the same" as a C++ destructor is not entirely correct,
though. Finalization can be waaaaay different than C++ destruction. <g>
I am not sure that anyone claimed that a C# destructor/finalizer has the
same semantics as C++.

I at least interpreted "same" as "same syntax".

Arne
Sep 15 '07 #8
"Arne Vajhøj" <ar**@vajhoej.dkwrote in message
news:46***********************@news.sunsite.dk...
Doug Semler wrote:
>"Arne Vajhøj" <ar**@vajhoej.dkwrote in message
news:46***********************@news.sunsite.dk. ..
>>Peter Duniho wrote:
WJ wrote:
>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
>
It means destructor (the same as C++).

No, it doesn't.

It declares the _finalizer_ which is not exactly the same as a C++
destructor.

In the two first edition of the C# standard it was named destructor.

In the third edition they renamed it to finalizer.

To my best knowledge they did not change any semantics.

In C#

To call it "the same" as a C++ destructor is not entirely correct,
though. Finalization can be waaaaay different than C++ destruction. <g>

I am not sure that anyone claimed that a C# destructor/finalizer has the
same semantics as C++.

I at least interpreted "same" as "same syntax".

*You* may have....*BUT* it is important to make sure that the OP understand
that even though it is the same syntax, it is not the same semantics.
Especially if he one were to read this particular message from top to bottom
without context. That's all I'm saying.

Finalizer, destructor....Tomat-oh, Tom-ah-toe. In C#, the semantics what
the function does is completely different than in C++. And that is what is
not "the same"

<g>

--
Doug Semler, MCPD
a.a. #705, BAAWA. EAC Guardian of the Horn of the IPU (pbuhh).
The answer is 42; DNRC o-
Gur Hfrarg unf orpbzr fb shyy bs penc gurfr qnlf, abbar rira
erpbtavmrf fvzcyr guvatf yvxr ebg13 nalzber. Fnq, vfa'g vg?

Sep 15 '07 #9
Doug Semler wrote:
[...]
Finalizer, destructor....Tomat-oh, Tom-ah-toe. In C#, the semantics
what the function does is completely different than in C++. And that is
what is not "the same"
And the post to which I replied read "It means destructor (the same as
C++)". The word "means" implies "semantics", whether that was intended
or not. That's what semantics is...the _meaning_.

I don't see how any reasonable interpretation infers "syntax" from the
word "means". I talk about "syntax" when I'm discussion how things are
written, and "semantics" when I'm discussion what those things mean.

But regardless, it's very important to understand that a finalizer isn't
a destructor. It's such an important difference, they even changed the
name to make that more clear.

Pete
Sep 15 '07 #10
"Peter Duniho" <Np*********@NnOwSlPiAnMk.comwrote in message
news:13*************@corp.supernews.com...
Doug Semler wrote:
>[...]
Finalizer, destructor....Tomat-oh, Tom-ah-toe. In C#, the semantics
what the function does is completely different than in C++. And that is
what is not "the same"

And the post to which I replied read "It means destructor (the same as
C++)". The word "means" implies "semantics", whether that was intended or
not. That's what semantics is...the _meaning_.

I don't see how any reasonable interpretation infers "syntax" from the
word "means". I talk about "syntax" when I'm discussion how things are
written, and "semantics" when I'm discussion what those things mean.

But regardless, it's very important to understand that a finalizer isn't a
destructor. It's such an important difference, they even changed the name
to make that more clear.

Pete

Pete,

I was talking syntax in terms of the original statement. This is the
problem with the English language. Here's two completely different
interpretations of "It [the ~] means destructor (the same as C++)":

1) As in the C++ language, the ~ character in front of the name makes that
the function is a destructor.
2) The ~ character in front of the function name makes the function act as a
destructor as in the a c++ language.

See how the syntax changes the semantics? In statement 1, the modification
is on the ~ character. In statement 2, the modification is on the word
"destructor". Which one is correct in terms of C#? Semantics and syntax
cannot be divorced from each other. (Which is probably why I like
programming languages better than natural languages)

--
Doug Semler, MCPD
a.a. #705, BAAWA. EAC Guardian of the Horn of the IPU (pbuhh).
The answer is 42; DNRC o-
Gur Hfrarg unf orpbzr fb shyy bs penc gurfr qnlf, abbar rira
erpbtavmrf fvzcyr guvatf yvxr ebg13 nalzber. Fnq, vfa'g vg?

Sep 15 '07 #11
Peter Duniho wrote:
Doug Semler wrote:
>[...]
Finalizer, destructor....Tomat-oh, Tom-ah-toe. In C#, the semantics
what the function does is completely different than in C++. And that
is what is not "the same"

And the post to which I replied read "It means destructor (the same as
C++)". The word "means" implies "semantics", whether that was intended
or not. That's what semantics is...the _meaning_.

I don't see how any reasonable interpretation infers "syntax" from the
word "means". I talk about "syntax" when I'm discussion how things are
written, and "semantics" when I'm discussion what those things mean.
Tilde is a syntactical element.

If someone ask what ^ means will you tell him that it means XOR or
will you tell him what XOR actually does ?

Arne
Oct 2 '07 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

22
by: Tuang | last post by:
I'm checking out Python as a candidate for replacing Perl as my "Swiss Army knife" tool. The longer I can remember the syntax for performing a task, the more likely I am to use it on the spot if...
75
by: David MacQuigg | last post by:
Seems like we need a simple way to extend Python syntax that doesn't break existing syntax or clash with any other syntax in Python, is easy to type, easy to read, and is clearly distinct from the...
24
by: Steven Bethard | last post by:
I think one of the biggest reasons we're having such problems coming to any agreement on decorator syntax is that each proposal makes a number of syntax decisions, not just one. For decorators, I...
7
by: Steven Bethard | last post by:
So here's the state of the decorator debate as I see it: *** Location GvR pretty strongly wants decorators before the function: ...
41
by: John Marshall | last post by:
How about the following, which I am almost positive has not been suggested: ----- class Klass: def __init__(self, name): self.name = name deco meth0: staticmethod def meth0(x):
0
by: CHristian Niss | last post by:
hi there, in a lot of user controls we are using "~" in server tags to reference objects like images <img src="~/images/something.gif" runat="server" />. with framework 1.0 the tilde got...
10
by: Shawn | last post by:
Hi, For a few years, I have been developing each of my clients websites using a seperate web site (unique IP) to solve problems with relative URL's between my local dev station and the...
4
by: ibiza | last post by:
Hi all, I have a problem which I don't understand with the "~" mark in a NavigateUrl property of an asp:HyperLink. I have this in a master page, to build the standard menu (rMenuItems is a...
4
by: =?Utf-8?B?QWxm?= | last post by:
Hello all, I am having trouble dealing with ~(tilde) in my .Net 1.1 web application, specially when it comes through the URL. For example, when someone requests the following URL:...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.