views:

132

answers:

3

Possible Duplicates:
What does placing a @ in front of a C# variable name do?
What’s the use/meaning of the @ character in variable names in C#?

As you can imagine, Googling or Binging for any phrase containing an '@' is difficult.

In creating a new web service, one of the members of the imported C# proxy class is prefixed with the @. For example:

plan.@event = new Insurance.Event();

I assume that it is Visual Studio's way resolving potential conflicts with reserved words because 'event' is a reserved word. Changing the property in the web service interface to something other than 'event' (i.e. 'healthevent') removes the @ from the property. Is this a correct assumption?

+8  A: 

Yes, names that conflict with C# keywords may be escaped with the @ character.

Bryan Watts
Actually all names may be preceded by the @ character, not only those that conflict with keywords.
Gabe
@Gabe: Fair enough.
Bryan Watts
+5  A: 

Yes that is correct. You can use keywords as identifiers as long as you include @ as a prefix.

See http://msdn.microsoft.com/en-us/library/x53a06bb.aspx for more info.

Iulian
+2  A: 

You are correct. See C# Keywords, section 2.4.2 Identifiers of the language specification, or string (C# Reference).

From the keywords topic:

Keywords are predefined, reserved identifiers that have special meanings to the compiler. They cannot be used as identifiers in your program unless they include @ as a prefix. For example, @if is a valid identifier but if is not because if is a keyword.

Jeff Sternal
@Jeff: Thanks for providing all of the links.
Mike Chess