@ - C# Reference
@ (C# Reference)
@ special character serves as a verbatim identifier. It can be used in the following ways:
To enable C# keywords to be used as identifiers. The
@character prefixes a code element that the compiler is to interpret as an identifier rather than a C# keyword. The following example uses the
@character to define an identifier named
forthat it uses in a
To indicate that a string literal is to be interpreted verbatim. The
@character in this instance defines a verbatim string literal. Simple escape sequences (such as
"\\"for a backslash), hexadecimal escape sequences (such as
"\x0041"for an uppercase A), and Unicode escape sequences (such as
"\u0041"for an uppercase A) are interpreted literally. Only a quote escape sequence (
"") is not interpreted literally; it produces a single quotation mark. Additionally, in case of a verbatim interpolated string brace escape sequences (
}}) are not interpreted literally; they produce single brace characters. The following example defines two identical file paths, one by using a regular string literal and the other by using a verbatim string literal. This is one of the more common uses of verbatim string literals.
The following example illustrates the effect of defining a regular string literal and a verbatim string literal that contain identical character sequences.
To enable the compiler to distinguish between attributes in cases of a naming conflict. An attribute is a class that derives from xref:System.Attribute. Its type name typically includes the suffix Attribute, although the compiler does not enforce this convention. The attribute can then be referenced in code either by its full type name (for example,
[InfoAttribute]or its shortened name (for example,
[Info]). However, a naming conflict occurs if two shortened attribute type names are identical, and one type name includes the Attribute suffix but the other does not. For example, the following code fails to compile because the compiler cannot determine whether the
InfoAttributeattribute is applied to the
Exampleclass. See CS1614 for more information.