This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!
2.5.1 Identifiers
These identifier rules exactly correspond to those recommended by the Unicode 2.1 standard except that underscore and similar characters are allowed as initial characters, formatting characters (class Cf) are not allowed in identifiers, and Unicode escape characters are permitted in identifiers.
- identifier:
- available-identifier
@ identifier-or-keyword
- available-identifier:
- An identifier-or-keyword that is not a keyword
- identifier-or-keyword:
- identifier-start-character identifier-part-charactersopt
- identifier-start-character:
- letter-character
underscore-character
- identifier-part-characters:
- identifier-part-character
identifier-part-characters identifier-part-character
- identifier-part-character:
- letter-character
combining-character
decimal-digit-character
underscore-character
- letter-character:
- A Unicode character of classes Lu, Ll, Lt, Lm, Lo, or Nl
A unicode-character-escape-sequence representing a character of classes Lu, Ll, Lt, Lm, Lo, or Nl
- combining-character:
- A Unicode character of classes Mn or Mc
A unicode-character-escape-sequence representing a character of classes Mn or Mcdecimal-digit-character:
A Unicode character of the class Nd
A unicode-character-escape-sequence representing a character of the class Nd
- underscore-character:
- A Unicode character of the class Pc
A unicode-character-escape-sequence representing a character of the class Pc
Examples of legal identifiers include "identifier1
", "_identifier2
", and "@if
".
The prefix "@
" enables the use of keywords as identifiers. The character @
is not actually part of the identifier, and so might be seen in other languages as a normal identifier, without the prefix. Use of the @
prefix for identifiers that are not keywords is permitted, but strongly discouraged as a matter of style.
The example:
class @class
{
static void @static(bool @bool) {
if (@bool)
Console.WriteLine("true");
else
Console.WriteLine("false");
}
}
class Class1
{
static void M {
@class.@static(true);
}
}
defines a class named "class
" with a static method named "static
" that takes a parameter named "bool
".