I discovered that you can start your variable name with a \'@\' character in C#. In my C# project I was using a web service (I added a web reference to my project) that was
You can use it to use the reserved keywords as variable name like
int @int = 3;
the compiler will ignores the @
and compile the variable as int
it is not a common practice to use thought
Another use case are extension methods. The first, special parameter can be distinguished to denote its real meaning with @this
name. An example:
public static TValue GetValueOrDefault<TKey, TValue>(
this IDictionary<TKey, TValue> @this,
TKey key,
TValue defaultValue)
{
if (!@this.ContainsKey(key))
{
return defaultValue;
}
return @this[key];
}
If we use a keyword as the name for an identifier, we get a compiler error “identifier expected, ‘Identifier Name’ is a keyword” To overcome this error, prefix the identifier with “@”. Such identifiers are verbatim identifiers. The character @ is not actually part of the identifier, so the identifier might be seen in other languages as a normal identifier, without the prefix