Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 277
Mike Chess Avatar asked Apr 16 '10 14:04

Mike Chess


People also ask

What is a member in a structure in C?

Structures (also called structs) are a way to group several related variables into one place. Each variable in the structure is known as a member of the structure. Unlike an array, a structure can contain many different data types (int, float, char, etc.).

What is member tag and variable name in a structure and what purpose?

A "structure declaration" names a type and specifies a sequence of variable values (called "members" or "fields" of the structure) that can have different types. An optional identifier, called a "tag," gives the name of the structure type and can be used in subsequent references to the structure type.

What is the naming convention for C?

Naming Conventions rules for Variables and Methods (Functions) are: It should begin with an alphabet. There may be more than one alphabet, but without any spaces between them. Digits may be used but only after alphabet.

What is union in C with example?

We use the union keyword to define unions. Here's an example: union car { char name[50]; int price; }; The above code defines a derived type union car .


2 Answers

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

like image 144
Bryan Watts Avatar answered Oct 31 '22 06:10

Bryan Watts


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.

like image 38
Iulian Avatar answered Oct 31 '22 05:10

Iulian