开发者

What is the purpose of @ as part of a member name in C#? [duplicate]

This question already has answers here: 开发者_JAVA百科 Closed 12 years ago.

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?


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


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜