9.4.2 Identifiers

9.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.
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
_ (the underscore character U+005F)
identifier-part-characters::
identifier-part-character
identifier-part-characters identifier-part-character
identifier-part-character::
letter-character
decimal-digit-character
connecting-character
combining-character
formatting-character
letter-character::
A Unicode character of classes Lu, Ll, Lt, Lm, Lo, or Nl
A unicode-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-escape-sequence representing a character of classes Mn or Mc
decimal-digit-character::
A Unicode character of the class Nd
A unicode-escape-sequence representing a character of the class Nd
C# LANGUAGE SPECIFICATION
56
connecting-character::
A Unicode character of the class Pc
A unicode-escape-sequence representing a character of the class Pc
formatting-character::
A Unicode character of the class Cf
A unicode-escape-sequence representing a character of the class Cf
[Note: For information on the Unicode character classes mentioned above,
see The Unicode Standard,
Verson 3.0, §4.5.) end note]
[Example: Examples of valid identifiers include .identifier1.,
._identifier2., and .@if.. end example]
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. [Note: Use of the @ prefix for identifiers that are not
keywords is permitted, but strongly discouraged
as a matter of style. end note]
[Example: The 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);
}
}
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]
Two identifiers are considered the same if they are identical after the
following transformations are applied, in
order:
. The prefix .@., if used, is removed.
. Each unicode-escape-sequence is transformed into its corresponding
Unicode character.
. Any 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. [Note: For example, an
implementation might provide extended keywords that begin with two
underscores. end note]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值