- •Foreword
- •Introduction
- •Scope
- •Conformance
- •Normative references
- •Definitions
- •Notational conventions
- •Acronyms and abbreviations
- •General description
- •Language overview
- •Getting started
- •Types
- •Predefined types
- •Conversions
- •Array types
- •Type system unification
- •Variables and parameters
- •Automatic memory management
- •Expressions
- •Statements
- •Classes
- •Constants
- •Fields
- •Methods
- •Properties
- •Events
- •Operators
- •Indexers
- •Instance constructors
- •Destructors
- •Static constructors
- •Inheritance
- •Static classes
- •Partial type declarations
- •Structs
- •Interfaces
- •Delegates
- •Enums
- •Namespaces and assemblies
- •Versioning
- •Extern Aliases
- •Attributes
- •Generics
- •Why generics?
- •Creating and consuming generics
- •Multiple type parameters
- •Constraints
- •Generic methods
- •Anonymous methods
- •Iterators
- •Lexical structure
- •Programs
- •Grammars
- •Lexical grammar
- •Syntactic grammar
- •Grammar ambiguities
- •Lexical analysis
- •Line terminators
- •Comments
- •White space
- •Tokens
- •Unicode escape sequences
- •Identifiers
- •Keywords
- •Literals
- •Boolean literals
- •Integer literals
- •Real literals
- •Character literals
- •String literals
- •The null literal
- •Operators and punctuators
- •Pre-processing directives
- •Conditional compilation symbols
- •Pre-processing expressions
- •Declaration directives
- •Conditional compilation directives
- •Diagnostic directives
- •Region control
- •Line directives
- •Pragma directives
- •Basic concepts
- •Application startup
- •Application termination
- •Declarations
- •Members
- •Namespace members
- •Struct members
- •Enumeration members
- •Class members
- •Interface members
- •Array members
- •Delegate members
- •Member access
- •Declared accessibility
- •Accessibility domains
- •Protected access for instance members
- •Accessibility constraints
- •Signatures and overloading
- •Scopes
- •Name hiding
- •Hiding through nesting
- •Hiding through inheritance
- •Namespace and type names
- •Unqualified name
- •Fully qualified names
- •Automatic memory management
- •Execution order
- •Types
- •Value types
- •The System.ValueType type
- •Default constructors
- •Struct types
- •Simple types
- •Integral types
- •Floating point types
- •The decimal type
- •The bool type
- •Enumeration types
- •Reference types
- •Class types
- •The object type
- •The string type
- •Interface types
- •Array types
- •Delegate types
- •Boxing and unboxing
- •Boxing conversions
- •Unboxing conversions
- •Variables
- •Variable categories
- •Static variables
- •Instance variables
- •Instance variables in classes
- •Instance variables in structs
- •Array elements
- •Value parameters
- •Reference parameters
- •Output parameters
- •Local variables
- •Default values
- •Definite assignment
- •Initially assigned variables
- •Initially unassigned variables
- •Precise rules for determining definite assignment
- •General rules for statements
- •Block statements, checked, and unchecked statements
- •Expression statements
- •Declaration statements
- •If statements
- •Switch statements
- •While statements
- •Do statements
- •For statements
- •Break, continue, and goto statements
- •Throw statements
- •Return statements
- •Try-catch statements
- •Try-finally statements
- •Try-catch-finally statements
- •Foreach statements
- •Using statements
- •Lock statements
- •General rules for simple expressions
- •General rules for expressions with embedded expressions
- •Invocation expressions and object creation expressions
- •Simple assignment expressions
- •&& expressions
- •|| expressions
- •! expressions
- •?: expressions
- •Anonymous method expressions
- •Yield statements
- •Variable references
- •Atomicity of variable references
- •Conversions
- •Implicit conversions
- •Identity conversion
- •Implicit numeric conversions
- •Implicit enumeration conversions
- •Implicit reference conversions
- •Boxing conversions
- •Implicit type parameter conversions
- •Implicit constant expression conversions
- •User-defined implicit conversions
- •Explicit conversions
- •Explicit numeric conversions
- •Explicit enumeration conversions
- •Explicit reference conversions
- •Unboxing conversions
- •User-defined explicit conversions
- •Standard conversions
- •Standard implicit conversions
- •Standard explicit conversions
- •User-defined conversions
- •Permitted user-defined conversions
- •Evaluation of user-defined conversions
- •User-defined implicit conversions
- •User-defined explicit conversions
- •Anonymous method conversions
- •Method group conversions
- •Expressions
- •Expression classifications
- •Values of expressions
- •Operators
- •Operator precedence and associativity
- •Operator overloading
- •Unary operator overload resolution
- •Binary operator overload resolution
- •Candidate user-defined operators
- •Numeric promotions
- •Unary numeric promotions
- •Binary numeric promotions
- •Member lookup
- •Base types
- •Function members
- •Argument lists
- •Overload resolution
- •Applicable function member
- •Better function member
- •Better conversion
- •Function member invocation
- •Invocations on boxed instances
- •Primary expressions
- •Literals
- •Simple names
- •Invariant meaning in blocks
- •Parenthesized expressions
- •Member access
- •Identical simple names and type names
- •Invocation expressions
- •Method invocations
- •Delegate invocations
- •Element access
- •Array access
- •Indexer access
- •This access
- •Base access
- •Postfix increment and decrement operators
- •The new operator
- •Object creation expressions
- •Array creation expressions
- •Delegate creation expressions
- •The typeof operator
- •The checked and unchecked operators
- •Default value expression
- •Anonymous methods
- •Anonymous method signatures
- •Anonymous method blocks
- •Outer variables
- •Captured outer variables
- •Instantiation of local variables
- •Anonymous method evaluation
- •Implementation example
- •Unary expressions
- •Unary plus operator
- •Unary minus operator
- •Logical negation operator
- •Bitwise complement operator
- •Prefix increment and decrement operators
- •Cast expressions
- •Arithmetic operators
- •Multiplication operator
- •Division operator
- •Remainder operator
- •Addition operator
- •Subtraction operator
- •Shift operators
- •Relational and type-testing operators
- •Integer comparison operators
- •Floating-point comparison operators
- •Decimal comparison operators
- •Boolean equality operators
- •Enumeration comparison operators
- •Reference type equality operators
- •String equality operators
- •Delegate equality operators
- •The is operator
- •The as operator
- •Logical operators
- •Integer logical operators
- •Enumeration logical operators
- •Boolean logical operators
- •Conditional logical operators
- •Boolean conditional logical operators
- •User-defined conditional logical operators
- •Conditional operator
- •Assignment operators
- •Simple assignment
- •Compound assignment
- •Event assignment
- •Expression
- •Constant expressions
- •Boolean expressions
- •Statements
- •End points and reachability
- •Blocks
- •Statement lists
- •The empty statement
- •Labeled statements
- •Declaration statements
- •Local variable declarations
- •Local constant declarations
- •Expression statements
- •Selection statements
- •The if statement
- •The switch statement
- •Iteration statements
- •The while statement
- •The do statement
- •The for statement
- •The foreach statement
- •Jump statements
- •The break statement
- •The continue statement
- •The goto statement
- •The return statement
- •The throw statement
- •The try statement
- •The checked and unchecked statements
- •The lock statement
- •The using statement
- •The yield statement
- •Namespaces
- •Compilation units
- •Namespace declarations
- •Extern alias directives
- •Using directives
- •Using alias directives
- •Using namespace directives
- •Namespace members
- •Type declarations
- •Qualified alias member
- •Classes
- •Class declarations
- •Class modifiers
- •Abstract classes
- •Sealed classes
- •Static classes
- •Class base specification
- •Base classes
- •Interface implementations
- •Class body
- •Partial declarations
- •Class members
- •Inheritance
- •The new modifier
- •Access modifiers
- •Constituent types
- •Static and instance members
- •Nested types
- •Fully qualified name
- •Declared accessibility
- •Hiding
- •this access
- •Reserved member names
- •Member names reserved for properties
- •Member names reserved for events
- •Member names reserved for indexers
- •Member names reserved for destructors
- •Constants
- •Fields
- •Static and instance fields
- •Readonly fields
- •Using static readonly fields for constants
- •Versioning of constants and static readonly fields
- •Volatile fields
- •Field initialization
- •Variable initializers
- •Static field initialization
- •Instance field initialization
- •Methods
- •Method parameters
- •Value parameters
- •Reference parameters
- •Output parameters
- •Parameter arrays
- •Static and instance methods
- •Virtual methods
- •Override methods
- •Sealed methods
- •Abstract methods
- •External methods
- •Method body
- •Method overloading
- •Properties
- •Static and instance properties
- •Accessors
- •Virtual, sealed, override, and abstract accessors
- •Events
- •Field-like events
- •Event accessors
- •Static and instance events
- •Virtual, sealed, override, and abstract accessors
- •Indexers
- •Indexer overloading
- •Operators
- •Unary operators
- •Binary operators
- •Conversion operators
- •Instance constructors
- •Constructor initializers
- •Instance variable initializers
- •Constructor execution
- •Default constructors
- •Private constructors
- •Optional instance constructor parameters
- •Static constructors
- •Destructors
- •Structs
- •Struct declarations
- •Struct modifiers
- •Struct interfaces
- •Struct body
- •Struct members
- •Class and struct differences
- •Value semantics
- •Inheritance
- •Assignment
- •Default values
- •Boxing and unboxing
- •Meaning of this
- •Field initializers
- •Constructors
- •Destructors
- •Static constructors
- •Struct examples
- •Database integer type
- •Database boolean type
- •Arrays
- •Array types
- •The System.Array type
- •Array creation
- •Array element access
- •Array members
- •Array covariance
- •Arrays and the generic IList interface
- •Array initializers
- •Interfaces
- •Interface declarations
- •Interface modifiers
- •Base interfaces
- •Interface body
- •Interface members
- •Interface methods
- •Interface properties
- •Interface events
- •Interface indexers
- •Interface member access
- •Fully qualified interface member names
- •Interface implementations
- •Explicit interface member implementations
- •Interface mapping
- •Interface implementation inheritance
- •Interface re-implementation
- •Abstract classes and interfaces
- •Enums
- •Enum declarations
- •Enum modifiers
- •Enum members
- •The System.Enum type
- •Enum values and operations
- •Delegates
- •Delegate declarations
- •Delegate instantiation
- •Delegate invocation
- •Exceptions
- •Causes of exceptions
- •The System.Exception class
- •How exceptions are handled
- •Common Exception Classes
- •Attributes
- •Attribute classes
- •Attribute usage
- •Positional and named parameters
- •Attribute parameter types
- •Attribute specification
- •Attribute instances
- •Compilation of an attribute
- •Run-time retrieval of an attribute instance
- •Reserved attributes
- •The AttributeUsage attribute
- •The Conditional attribute
- •Conditional Methods
- •Conditional Attribute Classes
- •The Obsolete attribute
- •Unsafe code
- •Unsafe contexts
- •Pointer types
- •Fixed and moveable variables
- •Pointer conversions
- •Pointers in expressions
- •Pointer indirection
- •Pointer member access
- •Pointer element access
- •The address-of operator
- •Pointer increment and decrement
- •Pointer arithmetic
- •Pointer comparison
- •The sizeof operator
- •The fixed statement
- •Stack allocation
- •Dynamic memory allocation
- •Generics
- •Generic class declarations
- •Type parameters
- •The instance type
- •Members of generic classes
- •Static fields in generic classes
- •Static constructors in generic classes
- •Accessing protected members
- •Overloading in generic classes
- •Parameter array methods and type parameters
- •Overriding and generic classes
- •Operators in generic classes
- •Nested types in generic classes
- •Generic struct declarations
- •Generic interface declarations
- •Uniqueness of implemented interfaces
- •Explicit interface member implementations
- •Generic delegate declarations
- •Constructed types
- •Type arguments
- •Open and closed types
- •Base classes and interfaces of a constructed type
- •Members of a constructed type
- •Accessibility of a constructed type
- •Conversions
- •Using alias directives
- •Generic methods
- •Generic method signatures
- •Virtual generic methods
- •Calling generic methods
- •Inference of type arguments
- •Using a generic method with a delegate
- •Constraints
- •Satisfying constraints
- •Member lookup on type parameters
- •Type parameters and boxing
- •Conversions involving type parameters
- •Iterators
- •Iterator blocks
- •Enumerator interfaces
- •Enumerable interfaces
- •Yield type
- •This access
- •Enumerator objects
- •The MoveNext method
- •The Current property
- •The Dispose method
- •Enumerable objects
- •The GetEnumerator method
- •Implementation example
- •Lexical grammar
- •Line terminators
- •White space
- •Comments
- •Unicode character escape sequences
- •Identifiers
- •Keywords
- •Literals
- •Operators and punctuators
- •Pre-processing directives
- •Syntactic grammar
- •Basic concepts
- •Types
- •Expressions
- •Statements
- •Classes
- •Structs
- •Arrays
- •Interfaces
- •Enums
- •Delegates
- •Attributes
- •Generics
- •Grammar extensions for unsafe code
- •Undefined behavior
- •Implementation-defined behavior
- •Unspecified behavior
- •Other Issues
- •Capitalization styles
- •Pascal casing
- •Camel casing
- •All uppercase
- •Capitalization summary
- •Word choice
- •Namespaces
- •Classes
- •Interfaces
- •Enums
- •Static fields
- •Parameters
- •Methods
- •Properties
- •Events
- •Case sensitivity
- •Avoiding type name confusion
- •Documentation Comments
- •Introduction
- •Recommended tags
- •<code>
- •<example>
- •<exception>
- •<list>
- •<para>
- •<param>
- •<paramref>
- •<permission>
- •<remarks>
- •<returns>
- •<seealso>
- •<summary>
- •<value>
- •Processing the documentation file
- •ID string format
- •ID string examples
- •An example
- •C# source code
- •Resulting XML
|
C# LANGUAGE SPECIFICATION |
|
|
1 |
file-name-character:: |
|
|
2 |
Any character except " (U+0022), and new-line-character |
|
|
3 |
pp-diagnostic:: |
|
|
4 |
whitespaceopt # whitespaceopt error whitespaceopt pp-message |
||
5 |
whitespaceopt # whitespaceopt |
warning whitespaceopt |
pp-message |
6 |
pp-message:: |
|
|
7 |
input-charactersopt new-line |
|
|
8 |
pp-region:: |
|
|
9 |
pp-start-region conditional-sectionopt pp-end-region |
|
|
10 |
pp-start-region:: |
|
|
11 |
whitespaceopt # whitespaceopt |
region whitespaceopt |
pp-message |
12 |
pp-end-region:: |
|
|
13 |
whitespaceopt # whitespaceopt |
endregion whitespaceopt pp-message |
|
14 |
pp-pragma: |
|
|
15 |
whitespaceopt # whitespaceopt |
pragma pp-pragma-text |
|
16 |
pp-pragma-text: |
|
|
17 |
new-line |
|
|
18 |
whitespace input-charactersopt |
new-line |
|
19A.2 Syntactic grammar
20A.2.1 Basic concepts
21compilation-unit:
22 |
extern-alias-directivesopt using-directivesopt global-attributesopt |
23 |
namespace-member-declarationsopt |
24 |
namespace-name: |
25 |
namespace-or-type-name |
26 |
type-name: |
27 |
namespace-or-type-name |
28 |
namespace-or-type-name: |
29 |
identifier type-argument-listopt |
30 |
namespace-or-type-name . identifier type-argument-listopt |
31 |
qualified-alias-member |
32A.2.2 Types
33type:
34 |
value-type |
35 |
reference-type |
36 |
type-parameter |
37 |
value-type: |
38 |
struct-type |
39 |
enum-type |
40 |
struct-type: |
41 |
type-name |
42 |
simple-type |
43 |
simple-type: |
44 |
numeric-type |
45 |
bool |
440
Annex A Grammar
1 |
numeric-type: |
2 |
integral-type |
3 |
floating-point-type |
4decimal
5integral-type:
6 |
sbyte |
7 |
byte |
8 |
short |
9 |
ushort |
10 |
int |
11 |
uint |
12 |
long |
13 |
ulong |
14char
15floating-point-type:
16 float
17double
18enum-type:
19 |
type-name |
20 |
reference-type: |
21 |
class-type |
22 |
interface-type |
23 |
array-type |
24 |
delegate-type |
25 |
class-type: |
26 |
type-name |
27 |
object |
28string
29interface-type:
30 |
type-name |
31 |
array-type: |
32 |
non-array-type rank-specifiers |
33 |
non-array-type: |
34 |
type |
35 |
rank-specifiers: |
36 |
rank-specifier |
37 |
rank-specifiers rank-specifier |
38 |
rank-specifier: |
39 |
[ dim-separatorsopt ] |
40 |
dim-separators: |
41 |
, |
42 |
dim-separators , |
43 |
delegate-type: |
44 |
type-name |
45 |
A.2.3 Variables |
46
47
variable-reference: expression
441
C# LANGUAGE SPECIFICATION
1A.2.4 Expressions
2argument-list:
3 |
argument |
4 |
argument-list , argument |
5 |
argument: |
6 |
expression |
7 |
ref variable-reference |
8out variable-reference
9primary-expression:
10 |
array-creation-expression |
11 |
primary-no-array-creation-expression |
12 |
primary-no-array-creation-expression: |
13 |
literal |
14 |
simple-name |
15 |
parenthesized-expression |
16 |
member-access |
17 |
invocation-expression |
18 |
element-access |
19 |
this-access |
20 |
base-access |
21 |
post-increment-expression |
22 |
post-decrement-expression |
23 |
object-creation-expression |
24 |
delegate-creation-expression |
25 |
typeof-expression |
26 |
checked-expression |
27 |
unchecked-expression |
28 |
default-value-expression |
29 |
anonymous-method-expression |
30 |
simple-name: |
31 |
identifier type-argument-listopt |
32 parenthesized-expression:
33( expression )
34member-access:
35 |
primary-expression . identifier type-argument-listopt |
|
|
|
||||
36 |
predefined-type . identifier type-argument-listopt |
|
|
|
||||
37 |
qualified-alias-member . identifier type-argument-listopt |
|
|
|
||||
38 |
predefined-type: one of |
|
|
|
|
|
|
|
39 |
bool |
byte |
char |
decimal |
double |
float |
int |
long |
40 |
object |
sbyte |
short |
string |
uint |
ulong |
ushort |
|
41 |
invocation-expression: |
|
|
|
|
|
|
|
42 |
primary-expression ( argument-listopt ) |
|
|
|
|
|||
43 |
element-access: |
|
|
|
|
|
|
|
44 |
primary-no-array-creation-expression [ expression-list ] |
|
|
|||||
45 |
expression-list: |
|
|
|
|
|
|
|
46 |
expression |
|
|
|
|
|
|
|
47 |
expression-list , expression |
|
|
|
|
|
||
48 |
this-access: |
|
|
|
|
|
|
|
49 |
this |
|
|
|
|
|
|
|
442
|
Annex A Grammar |
1 |
base-access: |
2 |
base . identifier type-argument-listopt |
3 |
base [ expression-list ] |
4 |
post-increment-expression: |
5 |
primary-expression ++ |
6 |
post-decrement-expression: |
7 |
primary-expression -- |
8 |
object-creation-expression: |
9 |
new type ( argument-listopt ) |
10 |
array-creation-expression: |
11 |
new non-array-type [ expression-list ] rank-specifiersopt array-initializeropt |
12new array-type array-initializer
13delegate-creation-expression:
14 |
new delegate-type ( expression ) |
15 |
typeof-expression: |
16 |
typeof ( type ) |
17typeof ( void )
18checked-expression:
19checked ( expression )
20unchecked-expression:
21unchecked ( expression )
22default-value-expression:
23 |
default ( primary-expression ) |
24 anonymous-method-expression:
25delegate anonymous-method-signatureopt block
26anonymous-method-signature:
27( anonymous-method-parameter-listopt )
28anonymous-method-parameter-list:
29 |
anonymous-method-parameter |
|
30 |
anonymous-method-parameter-list , anonymous-method-parameter |
|
31 |
anonymous-method-parameter: |
|
32 |
parameter-modifieropt type identifier |
|
33 |
unary-expression: |
|
34 |
primary-expression |
|
35 |
+ |
unary-expression |
36 |
- |
unary-expression |
37 |
! |
unary-expression |
38 |
~ |
unary-expression |
39 |
pre-increment-expression |
|
40 |
pre-decrement-expression |
|
41 |
cast-expression |
|
42 pre-increment-expression:
43++ unary-expression
44pre-decrement-expression:
45-- unary-expression
46cast-expression:
47 |
( type ) unary-expression |
443
|
C# LANGUAGE SPECIFICATION |
|
|
|
|
|
|
|
|||
1 |
multiplicative-expression: |
|
|
|
|
|
|
|
|||
2 |
unary-expression |
|
|
|
|
|
|
|
|
||
3 |
multiplicative-expression * unary-expression |
|
|
|
|||||||
4 |
multiplicative-expression / unary-expression |
|
|
|
|||||||
5 |
multiplicative-expression % unary-expression |
|
|
|
|||||||
6 |
additive-expression: |
|
|
|
|
|
|
|
|
||
7 |
multiplicative-expression |
|
|
|
|
|
|
|
|||
8 |
additive-expression + multiplicative-expression |
|
|
|
|||||||
9 |
additive-expression – multiplicative-expression |
|
|
|
|||||||
10 |
shift-expression: |
|
|
|
|
|
|
|
|
||
11 |
additive-expression |
|
|
|
|
|
|
|
|||
12 |
shift-expression << additive-expression |
|
|
|
|
||||||
13 |
shift-expression right-shift additive-expression |
|
|
|
|||||||
14 |
relational-expression: |
|
|
|
|
|
|
|
|
||
15 |
shift-expression |
|
|
|
|
|
|
|
|
||
16 |
relational-expression < shift-expression |
|
|
|
|
||||||
17 |
relational-expression > shift-expression |
|
|
|
|
||||||
18 |
relational-expression <= shift-expression |
|
|
|
|
||||||
19 |
relational-expression >= shift-expression |
|
|
|
|
||||||
20 |
relational-expression is type |
|
|
|
|
|
|
||||
21 |
relational-expression as type |
|
|
|
|
|
|
||||
22 |
equality-expression: |
|
|
|
|
|
|
|
|
||
23 |
relational-expression |
|
|
|
|
|
|
|
|||
24 |
equality-expression == relational-expression |
|
|
|
|||||||
25 |
equality-expression != relational-expression |
|
|
|
|||||||
26 |
and-expression: |
|
|
|
|
|
|
|
|
|
|
27 |
equality-expression |
|
|
|
|
|
|
|
|||
28 |
and-expression & equality-expression |
|
|
|
|
||||||
29 |
exclusive-or-expression: |
|
|
|
|
|
|
|
|||
30 |
and-expression |
|
|
|
|
|
|
|
|
||
31 |
exclusive-or-expression ^ and-expression |
|
|
|
|
||||||
32 |
inclusive-or-expression: |
|
|
|
|
|
|
|
|||
33 |
exclusive-or-expression |
|
|
|
|
|
|
|
|||
34 |
inclusive-or-expression | exclusive-or-expression |
|
|
|
|||||||
35 |
conditional-and-expression: |
|
|
|
|
|
|
|
|||
36 |
inclusive-or-expression |
|
|
|
|
|
|
|
|||
37 |
conditional-and-expression && inclusive-or-expression |
|
|
||||||||
38 |
conditional-or-expression: |
|
|
|
|
|
|
|
|||
39 |
conditional-and-expression |
|
|
|
|
|
|
||||
40 |
conditional-or-expression || conditional-and-expression |
|
|
||||||||
41 |
conditional-expression: |
|
|
|
|
|
|
|
|||
42 |
conditional-or-expression |
|
|
|
|
|
|
|
|||
43 |
conditional-or-expression ? expression : expression |
|
|
||||||||
44 |
assignment: |
|
|
|
|
|
|
|
|
|
|
45 |
unary-expression assignment-operator expression |
|
|
|
|||||||
46 |
assignment-operator: one of |
|
|
|
|
|
|
right-shift-assignment |
|||
47 |
= |
+= |
-= |
*= |
/= |
%= |
&= |
|= |
^= |
<<= |
|
444
