A. 语法

此附录是主文档中描述的词法和语法以及不安全代码的语法扩展的摘要。这里,各语法产生式是按它们在主文档中出现的顺序列出的。

A.1 词法文法

input:
input-sectionopt

input-section:
input-section-part
input-section   input-section-part

input-section-part:
input-elementsopt   new-line
pp-directive

input-elements:
input-element
input-elements   input-element

input-element:
whitespace
comment
token

A.1.1 行结束符

new-line:
Carriage return character (U+000D)
Line feed character (U+000A)
Carriage return character (U+000D) followed by
line feed character (U+000A)
Next
line character (U+0085)
Line separator character (U+2028)
Paragraph separator character (U+2029)

A.1.2 注释

comment:
single-line-comment
delimited-comment

single-line-comment:
//  
input-charactersopt

input-characters:
input-character
input-characters   input-character

input-character:
Any Unicode character except a new-line-character

new-line-character:
Carriage return character (U+000D)
Line feed character (U+000A)
Next
line character (U+0085)
Line separator character (U+2028)
Paragraph separator character (U+2029)

delimited-comment:
/*  
delimited-comment-textopt  
asterisks   /

delimited-comment-text:
delimited-comment-section
delimited-comment-text  
delimited-comment-section

delimited-comment-section:
/
asterisksopt  
not-slash-or-asterisk

asterisks:
*
asterisks   *

not-slash-or-asterisk:
Any Unicode character except / or *

A.1.3 空白

whitespace:
Any character with Unicode class Zs
Horizontal tab character (U+0009)
Vertical tab character (U+000B)
Form feed character (U+000C)

A.1.4 标记

token:
identifier
keyword
integer-literal
real-literal
character-literal
string-literal
operator-or-punctuator

A.1.5 Unicode 字符转义序列

unicode-escape-sequence:
\u  
hex-digit   hex-digit   hex-digit  
hex-digit
\U  
hex-digit   hex-digit   hex-digit 
hex-digit   hex-digit   hex-digit  
hex-digit   hex-digit

A.1.6 标识符

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

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

A.1.7 关键字

keyword:  one of
abstract    as            base          bool          break
byte        case          catch         char          checked
class           const         continue      decimal       default
delegate    do            double     else          enum
event           explicit      extern     false         finally
fixed           float         for        foreach       goto
if              implicit      in            int        interface
internal    is            lock          long          namespace
new         null          object     operator      out
override    params     private       protected  public
readonly    ref        return     sbyte         sealed
short           sizeof     stackalloc static     string
struct      switch     this          throw         true
try         typeof     uint          ulong         unchecked
unsafe      ushort     using         virtual       void
volatile    while

A.1.8 文本

literal:
boolean-literal
integer-literal
real-literal
character-literal
string-literal
null-literal

boolean-literal:
true
false

integer-literal:
decimal-integer-literal
hexadecimal-integer-literal

decimal-integer-literal:
decimal-digits   integer-type-suffixopt

decimal-digits:
decimal-digit
decimal-digits   decimal-digit

decimal-digit:  one of

1  2  3 
4  5  6 
7  8  9

integer-type-suffix:  one of

u  L  l 
UL  Ul  uL 
ul  LU  Lu 
lU  lu

hexadecimal-integer-literal:
0x   hex-digits  
integer-type-suffixopt
0X   hex-digits  
integer-type-suffixopt

hex-digits:
hex-digit
hex-digits   hex-digit

hex-digit:  one of
0  1 
2  3  4 
5  6  7 
8  9  A 
B  C  D 
E  F  a 
b  c  d 
e  f

real-literal:
decimal-digits   .   decimal-digits   exponent-partopt   real-type-suffixopt
.   decimal-digits   exponent-partopt   real-type-suffixopt
decimal-digits   exponent-part   real-type-suffixopt
decimal-digits   real-type-suffix

exponent-part:
e  
signopt  
decimal-digits
E   signopt   decimal-digits

sign:  one of

-

real-type-suffix:  one of

f  D  d 
M  m

character-literal:
'  
character   '

character:
single-character
simple-escape-sequence
hexadecimal-escape-sequence
unicode-escape-sequence

single-character:
 Any character
except ' (U+0027), \ (U+005C), and new-line-character

simple-escape-sequence:  one of
\'  \" 
\\  \0  \a 
\b  \f  \n 
\r  \t  \v

hexadecimal-escape-sequence:
\x  
hex-digit   hex-digitopt   hex-digitopt   hex-digitopt

string-literal:
regular-string-literal
verbatim-string-literal

regular-string-literal:
"  
regular-string-literal-charactersopt   "

regular-string-literal-characters:
regular-string-literal-character
regular-string-literal-characters  
regular-string-literal-character

regular-string-literal-character:
single-regular-string-literal-character
simple-escape-sequence
hexadecimal-escape-sequence
unicode-escape-sequence

single-regular-string-literal-character:
Any character except " (U+0022), \ (U+005C), and new-line-character

verbatim-string-literal:
@"  
verbatim-string-literal-charactersopt   "

verbatim-string-literal-characters:
verbatim-string-literal-character
verbatim-string-literal-characters  
verbatim-string-literal-character

verbatim-string-literal-character:
single-verbatim-string-literal-character
quote-escape-sequence

single-verbatim-string-literal-character:
any character except "

quote-escape-sequence:
""

null-literal:
null

A.1.9 运算符和标点符号

operator-or-punctuator:  one of
{    }      [      ]      (      )      .      ,      :      ;
+    -      *      /      %      &      |      ^      !      ~
=    <      >      ?      ??     ::     ++     --     &&     ||
->       ==     !=     <=     >=     +=     -=     *=     /=     %=
&=       |=     ^=     <<     <<= =>

right-shift:
>|>

right-shift-assignment:
>|>=

A.1.10 预处理指令

pp-directive:
pp-declaration
pp-conditional
pp-line
pp-diagnostic
pp-region
pp-pragma

conditional-symbol:
Any identifier-or-keyword except true or false

pp-expression:
whitespaceopt  
pp-or-expression   whitespaceopt

pp-or-expression:
pp-and-expression
pp-or-expression   whitespaceopt   ||  
whitespaceopt  
pp-and-expression

pp-and-expression:
pp-equality-expression
pp-and-expression   whitespaceopt   &&  
whitespaceopt  
pp-equality-expression

pp-equality-expression:
pp-unary-expression
pp-equality-expression   whitespaceopt   ==  
whitespaceopt  
pp-unary-expression
pp-equality-expression   whitespaceopt   !=  
whitespaceopt  
pp-unary-expression

pp-unary-expression:
pp-primary-expression
!  
whitespaceopt  
pp-unary-expression

pp-primary-expression:
true
false
conditional-symbol
(  
whitespaceopt  
pp-expression   whitespaceopt   )

pp-declaration:
whitespaceopt   #   whitespaceopt   define  
whitespace  
conditional-symbol   pp-new-line
whitespaceopt   #   whitespaceopt   undef  
whitespace  
conditional-symbol   pp-new-line

pp-new-line:
whitespaceopt  
single-line-commentopt  
new-line

pp-conditional:
pp-if-section   pp-elif-sectionsopt   pp-else-sectionopt   pp-endif

pp-if-section:
whitespaceopt   #   whitespaceopt   if  
whitespace   pp-expression   pp-new-line  
conditional-sectionopt

pp-elif-sections:
pp-elif-section
pp-elif-sections   pp-elif-section

pp-elif-section:
whitespaceopt   #   whitespaceopt   elif  
whitespace   pp-expression   pp-new-line  
conditional-sectionopt

pp-else-section:
whitespaceopt   #   whitespaceopt   else  
pp-new-line   conditional-sectionopt

pp-endif:
whitespaceopt   #   whitespaceopt   endif  
pp-new-line

conditional-section:
input-section
skipped-section

skipped-section:
skipped-section-part
skipped-section   skipped-section-part

skipped-section-part:
skipped-charactersopt  
new-line
pp-directive

skipped-characters:
whitespaceopt   not-number-sign   input-charactersopt

not-number-sign:
Any input-character except #

pp-diagnostic:
whitespaceopt   #   whitespaceopt   error  
pp-message
whitespaceopt   #   whitespaceopt   warning  
pp-message

pp-message:
new-line
whitespace   input-charactersopt
  new-line

pp-region:
pp-start-region   conditional-sectionopt   pp-end-region

pp-start-region:
whitespaceopt   #   whitespaceopt   region  
pp-message

pp-end-region:
whitespaceopt   #   whitespaceopt   endregion  
pp-message

pp-line:
whitespaceopt   #   whitespaceopt   line  
whitespace   line-indicator   pp-new-line

line-indicator:
decimal-digits   whitespace   file-name
decimal-digits
default
hidden

file-name:
"  
file-name-characters   "

file-name-characters:
file-name-character
file-name-characters   file-name-character

file-name-character:
Any input-character except "

pp-pragma:
whitespaceopt   #   whitespaceopt   pragma  
whitespace   pragma-body   pp-new-line

pragma-body:
pragma-warning-body

pragma-warning-body:
warning  
whitespace   warning-action
warning  
whitespace   warning-action   whitespace  
warning-list

warning-action:
disable
restore

warning-list:
decimal-digits
warning-list   whitespaceopt   ,  
whitespaceopt  
decimal-digits

A.2 句法文法

A.2.1 基本概念

namespace-name:
namespace-or-type-name

type-name:
namespace-or-type-name

namespace-or-type-name:
identifier   type-argument-listopt
namespace-or-type-name   .   identifier   type-argument-listopt
qualified-alias-member

A.2.2 类型

type:
value-type
reference-type
type-parameter

value-type:
struct-type
enum-type

struct-type:
type-name
simple-type
nullable-type

simple-type:
numeric-type
bool

numeric-type:
integral-type
floating-point-type
decimal

integral-type:
sbyte
byte
short
ushort
int
uint
long
ulong
char

floating-point-type:
float
double

nullable-type:
non-nullable-value-type   ?

non-nullable-value-type:
type

enum-type:
type-name

reference-type:
class-type
interface-type
array-type
delegate-type

class-type:
type-name
object
dynamic
string

interface-type:
type-name

rank-specifiers:
rank-specifier
rank-specifiers   rank-specifier

rank-specifier:
[  
dim-separatorsopt   ]

dim-separators:
,
dim-separators   ,

delegate-type:
type-name

type-argument-list:
<  
type-arguments   >

type-arguments:
type-argument
type-arguments   ,   type-argument

type-argument:
type

type-parameter:
identifier

A.2.3 变量

variable-reference:
expression

A.2.4 表达式

argument-list:
argument
argument-list   ,   argument

argument:
argument-nameopt  
argument-value

argument-name:
identifier   :

argument-value:
expression
ref  
variable-reference
out  
variable-reference

primary-expression:

primary-no-array-creation-expression
array-creation-expression

primary-no-array-creation-expression:
literal
simple-name
parenthesized-expression
member-access
invocation-expression
element-access
this-access
base-access
post-increment-expression
post-decrement-expression
object-creation-expression
delegate-creation-expression
anonymous-object-creation-expression
typeof-expression
 checked-expression
unchecked-expression
default-value-expression
anonymous-method-expression

simple-name:
identifier   type-argument-listopt

parenthesized-expression:
(  
expression   )

member-access:
primary-expression   .   identifier  type-argument-listopt
predefined-type   .   identifier  type-argument-listopt
qualified-alias-member   .   identifier

predefined-type:  one of
bool     byte       char       decimal    double float      int    long
object   sbyte      short      string uint       ulong      ushort

invocation-expression:
primary-expression   (   argument-listopt   )

element-access:
primary-no-array-creation-expression   [   argument-list   ]

this-access:
this

base-access:
base  
.  
identifier
base  
[  
argument-list   ]

post-increment-expression:
primary-expression   ++

post-decrement-expression:
primary-expression   --

object-creation-expression:
new  
type   (   argument-listopt   )  
object-or-collection-initializeropt
new  
type  
object-or-collection-initializer

object-or-collection-initializer:
object-initializer
collection-initializer

object-initializer:
{  
member-initializer-listopt  
}
{  
member-initializer-list   ,   }

member-initializer-list:
member-initializer
member-initializer-list   ,   member-initializer

member-initializer:
identifier   =   initializer-value

initializer-value:
expression
object-or-collection-initializer

collection-initializer:
{  
element-initializer-list   }
{  
element-initializer-list   ,   }

element-initializer-list:
element-initializer
element-initializer-list   ,   element-initializer

element-initializer:
non-assignment-expression
{  
expression-list   }

expression-list:
expression
expression-list   ,   expression

array-creation-expression:
new  
non-array-type   [   expression-list   ]  
rank-specifiersopt  
array-initializeropt
new  
array-type   array-initializer
new  
rank-specifier   array-initializer

delegate-creation-expression:
new  
delegate-type   (   expression   )

anonymous-object-creation-expression:
new  
anonymous-object-initializer

anonymous-object-initializer:
{  
member-declarator-listopt  
}
{  
member-declarator-list   ,   }

member-declarator-list:
member-declarator
member-declarator-list   ,   member-declarator

member-declarator:
simple-name
member-access
identifier   =   expression

typeof-expression:
typeof  
(  
type   )
typeof   (  
unbound-type-name   )
typeof ( void )

unbound-type-name:
identifier   generic-dimension-specifieropt
identifier   ::  
identifier  
generic-dimension-specifieropt
unbound-type-name   .  
identifier  
generic-dimension-specifieropt

generic-dimension-specifier:
<  
commasopt   >

commas:
,
commas   ,

checked-expression:
checked  
(  
expression   )

unchecked-expression:
unchecked  
(  
expression   )

default-value-expression:
default  
(  
type   )

unary-expression:
primary-expression
+  
unary-expression
-  
unary-expression
!  
unary-expression
~  
unary-expression
pre-increment-expression
pre-decrement-expression
cast-expression

pre-increment-expression:
++  
unary-expression

pre-decrement-expression:
--  
unary-expression

cast-expression:
(  
type   )   unary-expression

multiplicative-expression:
unary-expression
multiplicative-expression   *   unary-expression
multiplicative-expression   /   unary-expression
multiplicative-expression   %   unary-expression

additive-expression:
multiplicative-expression
additive-expression   +   multiplicative-expression
additive-expression   –  
multiplicative-expression

shift-expression:
additive-expression
shift-expression   <<  
additive-expression
shift-expression   right-shift   additive-expression

relational-expression:
shift-expression
relational-expression   <   shift-expression
relational-expression   >   shift-expression
relational-expression   <=   shift-expression
relational-expression   >=   shift-expression
relational-expression   is   type
relational-expression   as   type

equality-expression:
relational-expression
equality-expression   ==   relational-expression
equality-expression   !=   relational-expression

and-expression:
equality-expression
and-expression   &   equality-expression

exclusive-or-expression:
and-expression
exclusive-or-expression   ^   and-expression

inclusive-or-expression:
exclusive-or-expression
inclusive-or-expression   |   exclusive-or-expression

conditional-and-expression:
inclusive-or-expression
conditional-and-expression   &&  
inclusive-or-expression

conditional-or-expression:
conditional-and-expression
conditional-or-expression   ||   conditional-and-expression

null-coalescing-expression:
conditional-or-expression
conditional-or-expression   ??   null-coalescing-expression

conditional-expression:
null-coalescing-expression
null-coalescing-expression   ?   expression   :   expression

lambda-expression:
anonymous-function-signature   =>   anonymous-function-body

anonymous-method-expression:
delegate  
explicit-anonymous-function-signatureopt   block

anonymous-function-signature:
explicit-anonymous-function-signature
implicit-anonymous-function-signature

explicit-anonymous-function-signature:
(  
explicit-anonymous-function-parameter-listopt   )

explicit-anonymous-function-parameter-list:
explicit-anonymous-function-parameter
explicit-anonymous-function-parameter-list  
,  
explicit-anonymous-function-parameter

explicit-anonymous-function-parameter:
anonymous-function-parameter-modifieropt   type  
identifier

anonymous-function-parameter-modifier:

ref
out

implicit-anonymous-function-signature:
(   implicit-anonymous-function-parameter-listopt   )
implicit-anonymous-function-parameter

implicit-anonymous-function-parameter-list:
implicit-anonymous-function-parameter
implicit-anonymous-function-parameter-list  
,  
implicit-anonymous-function-parameter

implicit-anonymous-function-parameter:
identifier

anonymous-function-body:
expression
block

query-expression:
from-clause   query-body

from-clause:
from  
typeopt  
identifier   in   expression

query-body:
query-body-clausesopt  
select-or-group-clause  
query-continuationopt

query-body-clauses:
query-body-clause
query-body-clauses   query-body-clause

query-body-clause:
from-clause
let-clause
where-clause
join-clause
join-into-clause
orderby-clause

let-clause:
let  
identifier   =   expression

where-clause:
where  
boolean-expression

join-clause:
join  
typeopt  
identifier   in   expression   on  
expression   equals   expression

join-into-clause:
join  
typeopt  
identifier   in   expression   on  
expression   equals   expression   into  
identifier

orderby-clause:
orderby  
orderings

orderings:
ordering
orderings   ,  
ordering

ordering:
expression    ordering-directionopt

ordering-direction:
ascending
descending

select-or-group-clause:
select-clause
group-clause

select-clause:
select  
expression

group-clause:
group  
expression   by   expression

query-continuation:
into  
identifier   query-body

assignment:
unary-expression  
assignment-operator   expression

assignment-operator:
=
+=
-=
*=
/=
%=
&=
|=
^=
<<=
right-shift-assignment

expression:

non-assignment-expression
assignment

non-assignment-expression:
conditional-expression
lambda-expression
query-expression

constant-expression:
expression

boolean-expression:
expression

A.2.5 语句

statement:
labeled-statement
declaration-statement
embedded-statement

embedded-statement:
block
empty-statement
expression-statement
selection-statement
iteration-statement
jump-statement
try-statement
checked-statement
unchecked-statement
lock-statement
using-statement
yield-statement

block:
{  
statement-listopt   }

statement-list:
statement
statement-list   statement

empty-statement:
;

labeled-statement:
identifier   :  
statement

declaration-statement:
local-variable-declaration   ;
local-constant-declaration   ;

local-variable-declaration:
local-variable-type  
local-variable-declarators

local-variable-type:
type
var

local-variable-declarators:
local-variable-declarator
local-variable-declarators   ,   local-variable-declarator

local-variable-declarator:
identifier
identifier   =   local-variable-initializer

local-variable-initializer:
expression
array-initializer

local-constant-declaration:
const  
type   constant-declarators

constant-declarators:
constant-declarator
constant-declarators   ,   constant-declarator

constant-declarator:
identifier   =   constant-expression

expression-statement:
statement-expression   ;

statement-expression:
invocation-expression
object-creation-expression
assignment
post-increment-expression
post-decrement-expression
pre-increment-expression
pre-decrement-expression

selection-statement:
if-statement
switch-statement

if-statement:
if   (   boolean-expression   )  
embedded-statement
if   (   boolean-expression   )  
embedded-statement   else   embedded-statement

switch-statement:
switch  
(  
expression   )   switch-block

switch-block:
{  
switch-sectionsopt   }

switch-sections:
switch-section
switch-sections   switch-section

switch-section:
switch-labels   statement-list

switch-labels:
switch-label
switch-labels   switch-label

switch-label:
case  
constant-expression   :
default  
:

iteration-statement:
while-statement
do-statement
for-statement
foreach-statement

while-statement:
while  
(  
boolean-expression   )   embedded-statement

do-statement:
do  
embedded-statement   while   (  
boolean-expression   )   ;

for-statement:
for  
(  
for-initializeropt   ;   for-conditionopt   ;  
for-iteratoropt   )   embedded-statement

for-initializer:
local-variable-declaration
statement-expression-list

for-condition:
boolean-expression

for-iterator:
statement-expression-list

statement-expression-list:
statement-expression
statement-expression-list   ,   statement-expression

foreach-statement:
foreach  
(  
local-variable-type  
identifier   in   expression   )  
embedded-statement

jump-statement:
break-statement
continue-statement
goto-statement
return-statement
throw-statement

break-statement:
break  
;

continue-statement:
continue  
;

goto-statement:
goto  
identifier   ;
goto   case  
constant-expression   ;
goto  
default  
;

return-statement:
return  
expressionopt   ;

throw-statement:
throw  
expressionopt   ;

try-statement:
try 
 block   catch-clauses
try  
block   finally-clause
try  
block   catch-clauses   finally-clause

catch-clauses:
specific-catch-clauses  
general-catch-clauseopt
specific-catch-clausesopt  
general-catch-clause

specific-catch-clauses:
specific-catch-clause
specific-catch-clauses  
specific-catch-clause

specific-catch-clause:
catch  
(  
class-type   identifieropt   )  
block

general-catch-clause:
catch  
block

finally-clause:
finally  
block

checked-statement:
checked  
block

unchecked-statement:
unchecked 
 block

lock-statement:
lock  
(  
expression   )   embedded-statement

using-statement:
using  
(   
resource-acquisition   )    embedded-statement

resource-acquisition:
local-variable-declaration
expression

yield-statement:
yield  
return  
expression   ;
yield  
break  
;

A.2.6 命名空间

compilation-unit:
extern-alias-directivesopt  
using-directivesopt 
global-attributesopt
          namespace-member-declarationsopt

namespace-declaration:
namespace  
qualified-identifier  
namespace-body   ;opt

qualified-identifier:
identifier
qualified-identifier   .   identifier

namespace-body:
{  
extern-alias-directivesopt  
using-directivesopt  
namespace-member-declarationsopt   }

extern-alias-directives:
extern-alias-directive
extern-alias-directives  
extern-alias-directive

extern-alias-directive:
extern   alias  
identifier   ;

using-directives:
using-directive
using-directives   using-directive

using-directive:
using-alias-directive
using-namespace-directive

using-alias-directive:
using  
identifier   =   namespace-or-type-name   ;

using-namespace-directive:
using  
namespace-name   ;

namespace-member-declarations:
namespace-member-declaration
namespace-member-declarations  
namespace-member-declaration

namespace-member-declaration:
namespace-declaration
type-declaration

type-declaration:
class-declaration
struct-declaration
interface-declaration
enum-declaration
delegate-declaration

qualified-alias-member:
identifier   ::  
identifier   type-argument-listopt

A.2.7 类

class-declaration:
attributesopt  
class-modifiersopt   partialopt   class   identifier   type-parameter-listopt
          class-baseopt   type-parameter-constraints-clausesopt   class-body  
;opt

class-modifiers:
class-modifier
class-modifiers   class-modifier

class-modifier:
new
public
protected
internal
private
abstract
sealed
static

type-parameter-list:
<  
type-parameters   >

type-parameters:
attributesopt   type-parameter
type-parameters   ,   attributesopt   type-parameter

type-parameter:
identifier

class-base:
:  
class-type
:  
interface-type-list
:  
class-type   ,   interface-type-list

interface-type-list:
interface-type
interface-type-list   ,   interface-type

type-parameter-constraints-clauses:
type-parameter-constraints-clause
type-parameter-constraints-clauses  
type-parameter-constraints-clause

type-parameter-constraints-clause:
where  
type-parameter   :   type-parameter-constraints

type-parameter-constraints:
primary-constraint
secondary-constraints
constructor-constraint
primary-constraint   ,   secondary-constraints
primary-constraint   ,   constructor-constraint
secondary-constraints   ,   constructor-constraint
primary-constraint   ,   secondary-constraints   ,  
constructor-constraint

primary-constraint:
class-type
class
struct

secondary-constraints:
interface-type
type-parameter
secondary-constraints   ,   interface-type
secondary-constraints   ,   type-parameter

constructor-constraint:
new  
(   )

class-body:
{  
class-member-declarationsopt  
}

class-member-declarations:
class-member-declaration
class-member-declarations  
class-member-declaration

class-member-declaration:
constant-declaration
field-declaration
method-declaration
property-declaration
event-declaration
indexer-declaration
operator-declaration
constructor-declaration
destructor-declaration
static-constructor-declaration
type-declaration

constant-declaration:
attributesopt  
constant-modifiersopt  
const   type  
constant-declarators   ;

constant-modifiers:
constant-modifier
constant-modifiers   constant-modifier

constant-modifier:
new
public
protected
internal
private

constant-declarators:
constant-declarator
constant-declarators   ,   constant-declarator

constant-declarator:
identifier   =   constant-expression

field-declaration:
attributesopt  
field-modifiersopt  
type   variable-declarators   ;

field-modifiers:
field-modifier
field-modifiers   field-modifier

field-modifier:
new
public
protected
internal
private
static
readonly
volatile

variable-declarators:
variable-declarator
variable-declarators   ,   variable-declarator

variable-declarator:
identifier
identifier   =   variable-initializer

variable-initializer:
expression
array-initializer

method-declaration:
method-header   method-body

method-header:
attributesopt  
method-modifiersopt   partialopt  
return-type   member-name   type-parameter-listopt
          (  
formal-parameter-listopt  
)  
type-parameter-constraints-clausesopt

method-modifiers:
method-modifier
method-modifiers   method-modifier

method-modifier:
new
public
protected
internal
private
static
virtual
sealed
override
abstract
extern

return-type:
type
void

member-name:
identifier
interface-type   .   identifier

method-body:
block
;

formal-parameter-list:
fixed-parameters
fixed-parameters   ,   parameter-array
parameter-array

fixed-parameters:
fixed-parameter
fixed-parameters   ,   fixed-parameter

fixed-parameter:
attributesopt   parameter-modifieropt   type  
identifier   default-argumentopt

default-argument:
=  expression

parameter-modifier:
ref
out
this

parameter-array:
attributesopt   params   array-type   identifier

property-declaration:
attributesopt  
property-modifiersopt  
type   member-name   {  
accessor-declarations   }

property-modifiers:
property-modifier
property-modifiers   property-modifier

property-modifier:
new
public
protected
internal
private
static
virtual
sealed
override
abstract
extern

member-name:
identifier
interface-type   .   identifier

accessor-declarations:
get-accessor-declaration  
set-accessor-declarationopt
set-accessor-declaration  
get-accessor-declarationopt

get-accessor-declaration:
attributesopt  
accessor-modifieropt    get  
accessor-body

set-accessor-declaration:
attributesopt  
accessor-modifieropt   set   accessor-body

accessor-modifier:
protected
internal
private
protected   internal
internal   protected

accessor-body:
block
;

event-declaration:
attributesopt  
event-modifiersopt   event   type   variable-declarators   ;
attributesopt   event-modifiersopt   event  
type   member-name   {  
event-accessor-declarations   }

event-modifiers:
event-modifier
event-modifiers   event-modifier

event-modifier:
new
public
protected
internal
private
static
virtual
sealed
override
abstract
extern

event-accessor-declarations:
add-accessor-declaration  
remove-accessor-declaration
remove-accessor-declaration  
add-accessor-declaration

add-accessor-declaration:
attributesopt   add   block

remove-accessor-declaration:
attributesopt   remove   block

indexer-declaration:
attributesopt  
indexer-modifiersopt  
indexer-declarator   {   accessor-declarations   }

indexer-modifiers:
indexer-modifier
indexer-modifiers   indexer-modifier

indexer-modifier:
new
public
protected
internal
private
virtual
sealed
override
abstract
extern

indexer-declarator:
type   this  
[  
formal-parameter-list   ]
type   interface-type   .  
this  
[  
formal-parameter-list   ]

operator-declaration:
attributesopt  
operator-modifiers  
operator-declarator  
operator-body

operator-modifiers:
operator-modifier
operator-modifiers   operator-modifier

operator-modifier:
public
static
extern

operator-declarator:
unary-operator-declarator
binary-operator-declarator
conversion-operator-declarator

unary-operator-declarator:
type   operator  
overloadable-unary-operator   (   type   identifier  
)

overloadable-unary-operator:  one of
+   -  
!   ~   ++  
--   true   false

binary-operator-declarator:
type   operator  
overloadable-binary-operator   (   type   identifier  
,  
type   identifier   )

overloadable-binary-operator:
+
-
*
/
%
&
|
^
<<
right-shift
==
!=
>
<
>=
<=

conversion-operator-declarator:
implicit   operator  
type   (   type   identifier  
)
explicit  
operator  
type   (   type   identifier  
)

operator-body:
block
;

constructor-declaration:
attributesopt  
constructor-modifiersopt  
constructor-declarator  
constructor-body

constructor-modifiers:
constructor-modifier
constructor-modifiers  
constructor-modifier

constructor-modifier:
public
protected
internal
private
extern

constructor-declarator:
identifier   (  
formal-parameter-listopt  
)  
constructor-initializeropt

constructor-initializer:
:   base   (  
argument-listopt   )
:   this  
(  
argument-listopt   )

constructor-body:
block
;

static-constructor-declaration:
attributesopt  
static-constructor-modifiers 
identifier   (   )  
static-constructor-body

static-constructor-modifiers:
externopt static
static externopt

static-constructor-body:
block
;

destructor-declaration:
attributesopt   externopt   ~   identifier   (  
)   
destructor-body

destructor-body:
block
;

A.2.8 结构

struct-declaration:
attributesopt  
struct-modifiersopt   partialopt   struct   identifier   type-parameter-listopt
          struct-interfacesopt   type-parameter-constraints-clausesopt   struct-body  
;opt

struct-modifiers:
struct-modifier
struct-modifiers   struct-modifier

struct-modifier:
new
public
protected
internal
private

struct-interfaces:
:  
interface-type-list

struct-body:
{  
struct-member-declarationsopt   }

struct-member-declarations:
struct-member-declaration
struct-member-declarations  
struct-member-declaration

struct-member-declaration:
constant-declaration
field-declaration
method-declaration
property-declaration
event-declaration
indexer-declaration
operator-declaration
constructor-declaration
static-constructor-declaration
type-declaration

A.2.9 数组

array-type:
non-array-type   rank-specifiers

non-array-type:
type

rank-specifiers:
rank-specifier
rank-specifiers   rank-specifier

rank-specifier:
[  
dim-separatorsopt   ]

dim-separators:
,
dim-separators   ,

array-initializer:
{  
variable-initializer-listopt  
}
{  
variable-initializer-list   ,   }

variable-initializer-list:
variable-initializer
variable-initializer-list   ,   variable-initializer

variable-initializer:
expression
array-initializer

A.2.10 接口

interface-declaration:
attributesopt  
interface-modifiersopt  
partialopt   interface  
          identifier   variant-type-parameter-listopt   interface-baseopt
          type-parameter-constraints-clausesopt   interface-body   ;opt

interface-modifiers:
interface-modifier
interface-modifiers   interface-modifier

interface-modifier:
new
public
protected
internal
private

variant-type-parameter-list:
<  
variant-type-parameters   >

variant-type-parameters:
attributesopt 
variance-annotationopt  type-parameter
variant-type-parameters   ,   attributesopt   variance-annotationopt  type-parameter

variance-annotation:
in
out

interface-base:
:  
interface-type-list

interface-body:
{  
interface-member-declarationsopt   }

interface-member-declarations:
interface-member-declaration
interface-member-declarations  
interface-member-declaration

interface-member-declaration:
interface-method-declaration
interface-property-declaration
interface-event-declaration
interface-indexer-declaration

interface-method-declaration:
attributesopt   newopt  
return-type   identifier   type-parameter-list
          (  
formal-parameter-listopt  
)  
type-parameter-constraints-clausesopt   ;

interface-property-declaration:
attributesopt   newopt  
type   identifier   {  
interface-accessors   }

interface-accessors:
attributesopt   get   ;
attributesopt   set  
;
attributesopt   get  
;  
attributesopt   set   ;
attributesopt   set   ;  
attributesopt   get   ;

interface-event-declaration:
attributesopt   newopt   event   type   identifier  
;

interface-indexer-declaration:
attributesopt   newopt  
type   this   [  
formal-parameter-list   ]   {  
interface-accessors   }

A.2.11 枚举

enum-declaration:
attributesopt   enum-modifiersopt   enum  
identifier   enum-baseopt   enum-body  
;opt

enum-base:
:  
integral-type

enum-body:
{  
enum-member-declarationsopt  
}
{  
enum-member-declarations   ,   }

enum-modifiers:
enum-modifier
enum-modifiers   enum-modifier

enum-modifier:
new
public
protected
internal
private

enum-member-declarations:
enum-member-declaration
enum-member-declarations   ,   enum-member-declaration

enum-member-declaration:
attributesopt   identifier
attributesopt  
identifier   =   constant-expression

A.2.12 委托

delegate-declaration:
attributesopt  
delegate-modifiersopt  
delegate  
return-type  
          identifier  variant-type-parameter-listopt  
          (  
formal-parameter-listopt  
)  
type-parameter-constraints-clausesopt   ;

delegate-modifiers:
delegate-modifier
delegate-modifiers   delegate-modifier

delegate-modifier:
new
public
protected
internal
private

A.2.13 特性

global-attributes:
global-attribute-sections

global-attribute-sections:
global-attribute-section
global-attribute-sections  
global-attribute-section

global-attribute-section:
[  
global-attribute-target-specifier  
attribute-list   ]
[   global-attribute-target-specifier   attribute-list   ,  
]

global-attribute-target-specifier:
global-attribute-target   :

global-attribute-target:
assembly
module

attributes:
attribute-sections

attribute-sections:
attribute-section
attribute-sections   attribute-section

attribute-section:
[  
attribute-target-specifieropt   attribute-list   ]
[   attribute-target-specifieropt   attribute-list   ,  
]

attribute-target-specifier:
attribute-target   :

attribute-target:
field
event
method
param
property
return
type

attribute-list:
attribute
attribute-list   ,   attribute

attribute:
attribute-name   attribute-argumentsopt

attribute-name:
 type-name

attribute-arguments:
(   positional-argument-listopt   )
(   positional-argument-list   ,  
named-argument-list   )
(   named-argument-list   )

positional-argument-list:
positional-argument
positional-argument-list   ,   positional-argument

positional-argument:
argument-nameopt  
attribute-argument-expression

named-argument-list:
named-argument
named-argument-list   ,   named-argument

named-argument:
identifier   =  
attribute-argument-expression

attribute-argument-expression:
expression

A.3 不安全代码的语法扩展

class-modifier:
...
unsafe

struct-modifier:
...
unsafe

interface-modifier:
...
unsafe

delegate-modifier:
...
unsafe

field-modifier:
...
unsafe

method-modifier:
...
unsafe

property-modifier:
...
unsafe

event-modifier:
...
unsafe

indexer-modifier:
...
unsafe

operator-modifier:
...
unsafe

constructor-modifier:
...
unsafe

destructor-declaration:
attributesopt   externopt   unsafeopt   ~   identifier   (  
)   
destructor-body
attributesopt   unsafeopt   externopt   ~   identifier   (  
)   
destructor-body

static-constructor-modifiers:
externopt   unsafeopt   static
unsafeopt   externopt   static
externopt   static   unsafeopt
unsafeopt   static   externopt
static  
externopt   unsafeopt
static  
unsafeopt   externopt

embedded-statement:
...
unsafe-statement
fixed-statement

unsafe-statement:
unsafe  
block

type:
...
pointer-type

pointer-type:
unmanaged-type   *
void  
*

unmanaged-type:
type

primary-no-array-creation-expression:
...
pointer-member-access
pointer-element-access
sizeof-expression

unary-expression:
...
pointer-indirection-expression
addressof-expression

pointer-indirection-expression:
*  
unary-expression

pointer-member-access:
primary-expression   ->   identifier  type-argument-listopt

pointer-element-access:
primary-no-array-creation-expression   [   expression   ]

addressof-expression:
&  
unary-expression

sizeof-expression:
sizeof  
(  
unmanaged-type   )

fixed-statement:
fixed  
(  
pointer-type  
fixed-pointer-declarators   )   embedded-statement

fixed-pointer-declarators:
fixed-pointer-declarator
fixed-pointer-declarators   ,   fixed-pointer-declarator

fixed-pointer-declarator:
identifier   =  
fixed-pointer-initializer

fixed-pointer-initializer:
&  
variable-reference
expression

struct-member-declaration:

fixed-size-buffer-declaration

fixed-size-buffer-declaration:
attributesopt  
fixed-size-buffer-modifiersopt   fixed  
buffer-element-type
          fixed-size-buffer-declarators   ;

fixed-size-buffer-modifiers:
fixed-size-buffer-modifier
fixed-size-buffer-modifier  
fixed-size-buffer-modifiers

fixed-size-buffer-modifier:
new
public
protected
internal
private
unsafe

buffer-element-type:
type

fixed-size-buffer-declarators:
fixed-size-buffer-declarator
fixed-size-buffer-declarator  
fixed-size-buffer-declarators

fixed-size-buffer-declarator:
identifier   [  
constant-expression   ]

local-variable-initializer:

stackalloc-initializer

stackalloc-initializer:
stackalloc  
unmanaged-type   [   expression   ]

C# 语言规范_版本5.0 (第20章 附录B_语法)的更多相关文章

  1. C# 语言规范_版本5.0 (第19章 附录A_文档注释)

    A. 文档注释 C# 提供一种机制,使程序员可以使用含有 XML 文本的特殊注释语法为他们的代码编写文档.在源代码文件中,可以使用特定形式的注释来指导工具从这些注释及其后的源代码元素生成 XML.使用 ...

  2. C# 语言规范_版本5.0 (第21章 附录C_参考资料)

    A. 参考资料 Unicode 联合会.The Unicode Standard, Version 3.0(Unicode 标准 3.0 版).Addison-Wesley,Reading,Massa ...

  3. C# 语言规范_版本5.0 (第2章 词法结构)

    1. 词法结构 1.1 程序 C# 程序 (program) 由一个或多个源文件 (source file) 组成,源文件的正式名称是编译单元 (compilation unit)(第 9.1 节). ...

  4. C# 语言规范_版本5.0 (第10章 类)

    1. 类 类是一种数据结构,它可以包含数据成员(常量和字段).函数成员(方法.属性.事件.索引器.运算符.实例构造函数.静态构造函数和析构函数)以及嵌套类型.类类型支持继承,继承是一种机制,它使派生类 ...

  5. C# 语言规范_版本5.0 (第17章 特性)

    1. 特性 C# 语言的一个重要特征是使程序员能够为程序中定义的实体指定声明性信息.例如,类中方法的可访问性是通过使用 method-modifiers(public.protected.intern ...

  6. C# 语言规范_版本5.0 (第11章 结构)

    1. 结构 结构与类的相似之处在于,它们都表示可以包含数据成员和函数成员的数据结构.但是,与类不同,结构是一种值类型,并且不需要堆分配.结构类型的变量直接包含了该结构的数据,而类类型的变量所包含的只是 ...

  7. C# 语言规范_版本5.0 (第8章 语句)

    1. 语句 C# 提供各种语句.使用过 C 和 C++ 编程的开发人员熟悉其中大多数语句. statement: labeled-statement declaration-statement emb ...

  8. C# 语言规范_版本5.0 (第7章 表达式)

    1. 表达式 表达式是一个运算符和操作数的序列.本章定义语法.操作数和运算符的计算顺序以及表达式的含义. 1.1 表达式的分类 一个表达式可归类为下列类别之一: 值.每个值都有关联的类型. 变量.每个 ...

  9. C# 语言规范_版本5.0 (第6章 转换)

    1. 转换 转换(conversion) 使表达式可以被视为一种特定类型.转换可导致将给定类型的表达式视为具有不同的类型,或其可导致没有类型的表达式获得一种类型.转换可以是隐式的 (implicit) ...

随机推荐

  1. MFC双缓冲和裁剪问题导致闪烁

    问题描述: 应用场景:在对话框中,自定义一个MFC图形控件(为了描述方便,暂定为HSPaintControl),控件覆盖整个对话框的客户区,属于最底层的控件,在这之上放置了很多其他的小图形控件. 问题 ...

  2. 关于readonly

    当某个字段是引用类型,且该字段是readonly类型时,那么不可改变的是引用,而非引用的对象.如以下代码: public sealed class AType { public static read ...

  3. centos安装及配置

    centos安装 从网上下载最新的版本,用ultraiso做好系统盘,启动.安装过程没有什么可以说的,与其他发行版有点不同的是需要将安装包放到u盘根目录下(u盘容量最好大点,8~16G最好).开始没注 ...

  4. IE回车的怪异行为

    问题 IE浏览器在input中回车,会触发button按钮的click事件. 原因分析 IE浏览器中在input中回车相当于提交form,而button标签默认的类型是submit, 所以如果没有指定 ...

  5. cegui-0.8.2编译过程详解

    cegui 编译过程详解(cegui-0.8.2) cegui配置整了好长时间了,在一位大牛帮助下终于搞定了,网上的教程大多是老版本的,cegui-0.8.2版的配置寥寥无几,现在总结一下,献给正在纠 ...

  6. ubuntu下使用golang、qml与ubuntu sdk开发桌面应用

    ubuntu下使用golang.qml与ubuntu sdk开发桌面应用 (简单示例) 找了很长时间go的gui库,试了gtk,准备试qt的时候发现了这个qml库,试了下很好用. 准备工作 1.Go ...

  7. CMStepCounter Class Refernce

    CMStepCounter Class Refernce https://developer.apple.com/library/ios/documentation/CoreMotion/Refere ...

  8. xhEditor struts2实现图片上传

    xhEditor的环境搭建请参考http://blog.csdn.net/itmyhome1990/article/details/38422255,这时我们打开图片功能 是没有上传按钮的 如果想要出 ...

  9. C#执行cmd命令

    public class Console : IRun { public Console(){ ; } public string Result { get; set; } public string ...

  10. 一键搭键php网站环境的系统

    QzzmServer v2.0正式版发布 首先,感谢网友的热情的测评及反馈,现QzzmServer 2.0正式版已发布.有些朋友反馈制作一个服务器专用版本,在下已将此列入计划中,敬请大家耐心等候. Q ...