Skip to content
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
36 lines (25 sloc) 2.99 KB
title f1_keywords helpviewer_keywords ms.assetid
@ - C# Reference
@ special character [C#]
@ language element [C#]

@ (C# Reference)

The @ special character serves as a verbatim identifier. It can be used in the following ways:

  1. 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 for that it uses in a for loop.


  2. 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 ({{ and }}) 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.


  3. 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 Info or InfoAttribute attribute is applied to the Example class. See CS1614 for more information.


See also

You can’t perform that action at this time.