Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'@' symbol prefix on c# method call? [duplicate]

Possible Duplicate:
What's the use/meaning of the @ character in variable names in C#?

I was doing some .net development and I noticed I could add an @ symbol before any method call, i.e.:

var message = dog.@SayHello();

Just wondering, why is the reason this can be done ??

like image 618
Jose R. Cruz Avatar asked Aug 30 '11 15:08

Jose R. Cruz


People also ask

What does '@' mean in C#?

It marks the string as a verbatim string literal. In C#, a verbatim string is created using a special symbol @. @ is known as a verbatim identifier. If a string contains @ as a prefix followed by double quotes, then compiler identifies that string as a verbatim string and compile that string.

What is the use of in front of variable in C sharp?

Putting @ in front of a string tells the compuler not to process escape sequences found within the string.


1 Answers

The @ symbol can escape keywords and turn them into ordinary identifiers. Most .net languages support a mechanism like this since keywords are language dependent, and thus code written in other languages might collide with a keyword in your language without even noticing it.

Some people like using @this for the first parameter extension methods.

public static void MyExtension(this MyType @this)

another scenario where this can be useful is when using members to represent html attributes. Then without this feature you could not represent the class attribute.

like image 170
CodesInChaos Avatar answered Oct 01 '22 15:10

CodesInChaos