ECMA-334 C# Language Specification9.4.2: Identifiers |
The rules for identifiers given in this section correspond exactly to those recommended by the Unicode Standard Annex 15 except that underscore is allowed as an initial character (as is traditional in the C programming language), Unicode escape sequences are permitted in identifiers, and the "@" character is allowed as a prefix to enable keywords to be used as identifiers.
available-identifier @ identifier-or-keyword identifier-or-keyword that is not a keyword identifier-start-character identifier-part-charactersopt letter-character identifier-part-character identifier-part-characters identifier-part-character letter-character decimal-digit-character connecting-character combining-character formatting-character unicode-escape-sequence representing a character of classes Lu, Ll, Lt, Lm, Lo, or Nl unicode-escape-sequence representing a character of classes Mn or Mc unicode-escape-sequence representing a character of the class Nd unicode-escape-sequence representing a character of the class Pc unicode-escape-sequence representing a character of the class Cf An identifier in a conforming program must be in the canonical format defined by Unicode Normalization Form C, as defined by Unicode Standard Annex 15. The behavior when encountering an identifier not in Normalization Form C is implementation-defined; however, a diagnostic is not required.
The prefix "@" enables the use of keywords as identifiers, which is useful when interfacing with other programming languages. 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. An identifier with an @ prefix is called a verbatim identifier.
defines a class named "class" with a static method named "static" that takes a parameter named "bool". Note that since Unicode escapes are not permitted in keywords, the token "cl\u0061ss" is an identifier, and is the same identifier as "@class". end example]
class @class
{
public static void @static(bool @bool) {
if (@bool)
System.Console.WriteLine("true");
else
System.Console.WriteLine("false");
}
}
class Class1
{
static void M() {
cl\u0061ss.st\u0061tic(true);
}
}
Two identifiers are considered the same if they are identical after the following transformations are applied, in order:
unicode-escape-sequence is transformed into its corresponding Unicode character. formatting-characters are removed. Identifiers containing two consecutive underscore characters (U+005F) are reserved for use by the implementation; however, no diagnostic is required if such an identifier is defined.