- •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
Annex A Grammar
1 |
type-parameter-constraints-clauses: |
2 |
type-parameter-constraints-clause |
3 |
type-parameter-constraints-clauses type-parameter-constraints-clause |
4 |
type-parameter-constraints-clause: |
5 |
where type-parameter : type-parameter-constraints |
6 |
type-parameter-constraints: |
7 |
primary-constraint |
8 |
secondary-constraints |
9 |
constructor-constraint |
10 |
primary-constraint , secondary-constraints |
11 |
primary-constraint , constructor-constraint |
12 |
secondary-constraints , constructor-constraint |
13 |
primary-constraint , secondary-constraints , constructor-constraint |
14 |
primary-constraint: |
15 |
class-type |
16 |
class |
17struct
18secondary-constraints:
19 |
interface-type |
20 |
type-parameter |
21 |
secondary-constraints , interface-type |
22 |
secondary-constraints , type-parameter |
23 constructor-constraint:
24new ( )
25A.3 Grammar extensions for unsafe code
26embedded-statement:
27 |
... |
28 |
unsafe-statement |
29 unsafe-statement:
30unsafe block
31type:
32 |
value-type |
33 |
reference-type |
34 |
pointer-type |
35 |
pointer-type: |
36 |
unmanaged-type * |
37void *
38unmanaged-type:
39 |
type |
40 |
primary-no-array-creation-expression: |
41 |
... |
42 |
pointer-member-access |
43 |
pointer-element-access |
44 |
sizeof-expression |
45 |
unary-expression: |
46 |
... |
47 |
pointer-indirection-expression |
48 |
addressof-expression |
459
C# LANGUAGE SPECIFICATION
1 pointer-indirection-expression:
2* unary-expression
3pointer-member-access:
4 |
primary-expression -> identifier type-argument-listopt |
5 |
pointer-element-access: |
6 |
primary-no-array-creation-expression [ expression ] |
7 addressof-expression:
8& unary-expression
9sizeof-expression:
10sizeof ( unmanaged-type )
11embedded-statement:
12 |
... |
13 |
fixed-statement |
14 |
fixed-statement: |
15 |
fixed ( pointer-type fixed-pointer-declarators ) embedded-statement |
16 |
fixed-pointer-declarators: |
17 |
fixed-pointer-declarator |
18 |
fixed-pointer-declarators , fixed-pointer-declarator |
19 |
fixed-pointer-declarator: |
20 |
identifier = fixed-pointer-initializer |
21 |
fixed-pointer-initializer: |
22 |
& variable-reference |
23 |
expression |
24 |
variable-initializer: |
25 |
expression |
26 |
array-initializer |
27 |
stackalloc-initializer |
28 |
stackalloc-initializer: |
29 |
stackalloc unmanaged-type [ expression ] |
30 |
End of informative text. |
460
Annex B Portability issues
1Annex B. Portability issues
2This clause is informative.
3This annex collects some information about portability that appears in this International Standard.
4B.1 Undefined behavior
5A program that does not contain any occurrences of the unsafe modifier cannot exhibit any undefined
6behavior.
7The behavior is undefined in the following circumstances:
81. When dereferencing the result of converting one pointer type to another and the resulting pointer is not
9correctly aligned for the pointed-to type. (§25.4)
102. When the unary * operator is applied to a pointer containing an invalid value (§25.5.1).
113. When a pointer is subscripted to access an out-of-bounds element (§25.5.3).
124. Modifying objects of managed type through fixed pointers (§25.6)
135. The initial content of memory allocated by stackalloc (§25.7).
146. Attempting to allocate a negative number of items using stackalloc (§25.7).
15B.2 Implementation-defined behavior
16A conforming implementation is required to document its choice of behavior in each of the areas listed in
17this subclause. The following are implementation-defined:
181. The behavior when an identifier not in Normalization Form C is encountered (§9.4.2).
192. The purpose of a line-indicator with an identifier-or-keyword whose value does not equal default
20(§9.5.7).
213. The interpretation of the input-characters in the pp-pragma-text of a #pragma directive (§9.5.8).
224. The values of any application parameters passed to Main by the host environment prior to application
23startup (§10.1).
245. Whether a System.ArithmeticException (or a subclass thereof) is thrown or the overflow goes
25unreported with the resulting value being that of the left operand, when in an unchecked context and
26the left operand of an integer division is the maximum negative int or long value and the right
27operand is –1. (§14.7.2).
286. The mechanism by which linkage to an external function is achieved (§17.5.7).
297. The impact of thread termination when no matching catch clause is found for an exception and the code
30that initially started that thread is reached. (§23.3)
318. The purpose of attribute target specifiers other than those identified by this standard (§24.2).
329. The mappings between pointers and integers (§25.4).
3310. The effect of applying the unary * operator to a null pointer (§25.5.1).
3411. The behavior when pointer arithmetic overflows the domain of the pointer type (§25.5.5).
3512. The result of the sizeof operator for nonpre-defined value types (§25.5.8).
461
C# LANGUAGE SPECIFICATION
113. The behavior of the fixed statement if the array expression is null or if the array has zero
2elements (§25.6).
314. The behavior of the fixed statement if the string expression is null (§25.6).
415. The value returned when a stack allocation of size zero is made (§25.7).
5B.3 Unspecified behavior
61. The time at which the destructor (if any) for an object is run, once that object has become eligible for
7destruction (§10.9).
82. The value of the result when converting out-of-range values from float or double values to an
9integral type in an unchecked context (§13.2.1).
103. The layout of arrays, except in an unsafe context (§14.5.10.2).
114. Whether there is any way to execute the block of an anonymous method other than through evaluation
12and invocation of the anonymous-method-expression (§14.5.14.2).
135. The invocation list of a delegate produced from an anonymous-method-expression contains a single
14entry. The exact target object and target method of the delegate are unspecified (§14.5.14.4).
156. The exact timing of static field initialization (§17.4.5.1).
167. The attributes of a type declared in multiple parts are determined by combining, in an unspecified
17order, the attributes of each of its parts (§24.2).
188. The order in which members are packed into a struct (§25.5.8).
199. When an enumerator object is in the running state, the result of invoking MoveNext is unspecified
20(§27.2.1).
2110. When an enumerator object is in the before, running, or after states, the result of accessing Current is
22unspecified (§27.2.2).
2311. When an enumerator object is in the running state, the result of invoking Dispose is unspecified
24(§27.2.3).
25B.4 Other Issues
261. The exact results of floating-point expression evaluation can vary from one implementation to another,
27because an implementation is permitted to evaluate such expressions using a greater range and/or
28precision than is required. (§11.1.6)
292. The CLI reserves certain signatures for compatibility with other programming languages. (§17.2.7)
30End of informative text.
462
