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 ??
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.
Putting @ in front of a string tells the compuler not to process escape sequences found within the string.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With