Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

What's the @ operator do?

0 views
Skip to first unread message

stork

unread,
May 15, 2008, 12:16:30 PM5/15/08
to
If I see a piece of code like:

someobject.stringProperty = @mycontrol.Text;

What does the @ do in that case?

Is that a clone operator?

Peter Duniho

unread,
May 15, 2008, 12:30:30 PM5/15/08
to

It's hard to say whether that's even valid code. But assuming it is, it's
indicating to the compiler that the variable "@mycontrol" should not be
confused with some built-in keyword "mycontrol".

Usually you'd only see that in some sort of auto-generated code.
Hand-written code would normally only use "@" if the variable name did in
fact conflict with an existing C# keyword.

Pete

Alcides

unread,
May 15, 2008, 1:08:32 PM5/15/08
to

the @ can be used with strings. not sure if can be used with var
names.
For strings you can use for @"c:\Docs\Source\a.txt" rather than "c:\
\Docs\\Source\\a.txt"

Al Schulz
http://alsql.blogspot.com

.\\axxx

unread,
May 15, 2008, 9:45:47 PM5/15/08
to

The prefix "@" enables the use of keywords as identifiers, which is
useful when interfacing with other programming languages. The
character @ is not actually part of the identifier, so the identifier
might be seen in other languages as a normal identifier, without the
prefix. An identifier with an @ prefix is called a verbatim
identifier. Use of the @ prefix for identifiers that are not keywords
is permitted, but strongly discouraged as a matter of style.
From MSDN
http://msdn.microsoft.com/en-us/library/aa664670(VS.71).aspx

0 new messages