Baixe ECMA-334 C# Language Specification C# Language e outras Notas de estudo em PDF para Sistemas de Informação, somente na Docsity!
ECMA-
4 th^ Edition / June 2006
C# Language
Specification
.
Table of Contents
Table of Contents
Foreword ...................................................................................................................................................... xvii
- Scope Introduction xix
- Conformance
- Normative references
- Definitions
- Notational conventions................................................................................................................................
- Acronyms and abbreviations
- General description
- Language overview....................................................................................................................................
- 8.1 Getting started
- 8.2 Types
- 8.2.1 Predefined types
- 8.2.2 Conversions
- 8.2.3 Array types
- 8.2.4 Type system unification
- 8.3 Variables and parameters
- 8.4 Automatic memory management
- 8.5 Expressions
- 8.6 Statements
- 8.7 Classes
- 8.7.1 Constants
- 8.7.2 Fields
- 8.7.3 Methods
- 8.7.4 Properties
- 8.7.5 Events
- 8.7.6 Operators
- 8.7.7 Indexers
- 8.7.8 Instance constructors
- 8.7.9 Finalizers
- 8.7.10 Static constructors
- 8.7.11 Inheritance
- 8.7.12 Static classes
- 8.7.13 Partial type declarations
- 8.8 Structs
- 8.9 Interfaces
- 8.10 Delegates
- 8.11 Enums
- 8.12 Namespaces and assemblies
- 8.13 Versioning
- 8.14 Extern aliases.......................................................................................................................................
- 8.15 Attributes
- 8.16 Generics...............................................................................................................................................
- 8.16.1 Why generics? C# LANGUAGE SPECIFICATION
- 8.16.2 Creating and consuming generics
- 8.16.3 Multiple type parameters..............................................................................................................
- 8.16.4 Constraints
- 8.16.5 Generic methods
- 8.17 Anonymous methods
- 8.18 Iterators
- 8.19 Nullable types......................................................................................................................................
- Lexical structure........................................................................................................................................
- 9.1 Programs
- 9.2 Grammars
- 9.2.1 Lexical grammar
- 9.2.2 Syntactic grammar
- 9.2.3 Grammar ambiguities
- 9.3 Lexical analysis
- 9.3.1 Line terminators
- 9.3.2 Comments
- 9.3.3 White space
- 9.4 Tokens
- 9.4.1 Unicode escape sequences
- 9.4.2 Identifiers
- 9.4.3 Keywords
- 9.4.4 Literals
- 9.4.4.1 Boolean literals........................................................................................................................
- 9.4.4.2 Integer literals..........................................................................................................................
- 9.4.4.3 Real literals..............................................................................................................................
- 9.4.4.4 Character literals
- 9.4.4.5 String literals
- 9.4.4.6 The null literal
- 9.4.5 Operators and punctuators..............................................................................................................
- 9.5 Pre-processing directives.......................................................................................................................
- 9.5.1 Conditional compilation symbols
- 9.5.2 Pre-processing expressions
- 9.5.3 Declaration directives.....................................................................................................................
- 9.5.4 Conditional compilation directives
- 9.5.5 Diagnostic directives
- 9.5.6 Region control
- 9.5.7 Line directives
- 9.5.8 Pragma directives
- Basic concepts
- 10.1 Application startup
- 10.2 Application termination.......................................................................................................................
- 10.3 Declarations.........................................................................................................................................
- 10.4 Members
- 10.4.1 Namespace members
- 10.4.2 Struct members
- 10.4.3 Enumeration members
- 10.4.4 Class members
- 10.4.5 Interface members
- 10.4.6 Array members
- 10.4.7 Delegate members
- 10.5 Member access
- 10.5.1 Declared accessibility...................................................................................................................
- 10.5.2 Accessibility domains Table of Contents
- 10.5.3 Protected access for instance members
- 10.5.4 Accessibility constraints...............................................................................................................
- 10.6 Signatures and overloading
- 10.7 Scopes
- 10.7.1 Name hiding
- 10.7.1.1 Hiding through nesting
- 10.7.1.2 Hiding through inheritance....................................................................................................
- 10.8 Namespace and type names...............................................................................................................
- 10.8.1 Unqualified name
- 10.8.2 Fully qualified names
- 10.9 Automatic memory management
- 10.10 Execution order
- Types
- 11.1 Value types
- 11.1.1 The System.ValueType type
- 11.1.2 Default constructors
- 11.1.3 Struct types
- 11.1.4 Simple types
- 11.1.5 Integral types
- 11.1.6 Floating point types
- 11.1.7 The decimal type
- 11.1.8 The bool type
- 11.1.9 Enumeration types......................................................................................................................
- 11.2 Reference types
- 11.2.1 Class types..................................................................................................................................
- 11.2.2 The object type
- 11.2.3 The string type
- 11.2.4 Interface types
- 11.2.5 Array types
- 11.2.6 Delegate types
- 11.2.7 The null type
- 11.3 Boxing and unboxing
- 11.3.1 Boxing conversions
- 11.3.2 Unboxing conversions................................................................................................................
- 11.4 Nullable types....................................................................................................................................
- 11.4.1 Members.....................................................................................................................................
- 11.4.2 Implemented interfaces
- Variables
- 12.1 Variable categories
- 12.1.1 Static variables
- 12.1.2 Instance variables
- 12.1.2.1 Instance variables in classes
- 12.1.2.2 Instance variables in structs.................................................................................................
- 12.1.3 Array elements
- 12.1.4 Value parameters........................................................................................................................
- 12.1.5 Reference parameters
- 12.1.6 Output parameters
- 12.1.7 Local variables
- 12.2 Default values
- 12.3 Definite assignment
- 12.3.1 Initially assigned variables
- 12.3.2 Initially unassigned variables
- 12.3.3 Precise rules for determining definite assignment C# LANGUAGE SPECIFICATION
- 12.3.3.1 General rules for statements
- 12.3.3.2 Block statements, checked, and unchecked statements
- 12.3.3.3 Expression statements
- 12.3.3.4 Declaration statements
- 12.3.3.5 If statements
- 12.3.3.6 Switch statements
- 12.3.3.7 While statements
- 12.3.3.8 Do statements
- 12.3.3.9 For statements
- 12.3.3.10 Break, continue, and goto statements
- 12.3.3.11 Throw statements
- 12.3.3.12 Return statements
- 12.3.3.13 Try-catch statements
- 12.3.3.14 Try-finally statements
- 12.3.3.15 Try-catch-finally statements
- 12.3.3.16 Foreach statements
- 12.3.3.17 Using statements
- 12.3.3.18 Lock statements
- 12.3.3.19 General rules for simple expressions
- 12.3.3.20 General rules for expressions with embedded expressions
- 12.3.3.21 Invocation expressions and object creation expressions
- 12.3.3.22 Simple assignment expressions
- 12.3.3.23 && expressions
- 12.3.3.24 || expressions......................................................................................................................
- 12.3.3.25! expressions
- 12.3.3.26 ?: expressions
- 12.3.3.27 Anonymous method expressions
- 12.3.3.28 Yield statements
- 12.3.3.29 ?? expressions....................................................................................................................
- 12.4 Variable references
- 12.5 Atomicity of variable references
- Conversions............................................................................................................................................
- 13.1 Implicit conversions
- 13.1.1 Identity conversion
- 13.1.2 Implicit numeric conversions
- 13.1.3 Implicit enumeration conversions
- 13.1.4 Implicit reference conversions
- 13.1.5 Boxing conversions
- 13.1.6 Implicit type parameter conversions
- 13.1.7 Implicit constant expression conversions...................................................................................
- 13.1.8 User-defined implicit conversions
- 13.2 Explicit conversions
- 13.2.1 Explicit numeric conversions
- 13.2.2 Explicit enumeration conversions
- 13.2.3 Explicit reference conversions
- 13.2.4 Unboxing conversions................................................................................................................
- 13.2.5 Explicit type parameter conversions
- 13.2.6 User-defined explicit conversions
- 13.3 Standard conversions.........................................................................................................................
- 13.3.1 Standard implicit conversions
- 13.3.2 Standard explicit conversions
- 13.4 User-defined conversions
- 13.4.1 Permitted user-defined conversions
- 13.4.2 Evaluation of user-defined conversions Table of Contents
- 13.4.3 User-defined implicit conversions
- 13.4.4 User-defined explicit conversions
- 13.5 Anonymous method conversions
- 13.6 Method group conversions
- 13.7 Conversions involving nullable types
- 13.7.1 Null type conversions
- 13.7.2 Nullable conversions
- 13.7.3 Lifted conversions
- Expressions
- 14.1 Expression classifications
- 14.1.1 Values of expressions.................................................................................................................
- 14.2 Operators
- 14.2.1 Operator precedence and associativity
- 14.2.2 Operator overloading
- 14.2.3 Unary operator overload resolution
- 14.2.4 Binary operator overload resolution...........................................................................................
- 14.2.5 Candidate user-defined operators
- 14.2.6 Numeric promotions...................................................................................................................
- 14.2.6.1 Unary numeric promotions..................................................................................................
- 14.2.6.2 Binary numeric promotions
- 14.2.7 Lifted operators
- 14.3 Member lookup
- 14.4 Function members
- 14.4.1 Argument lists
- 14.4.2 Overload resolution
- 14.4.2.1 Applicable function member
- 14.4.2.2 Better function member.......................................................................................................
- 14.4.2.3 Better conversion
- 14.4.3 Function member invocation......................................................................................................
- 14.4.3.1 Invocations on boxed instances
- 14.5 Primary expressions
- 14.5.1 Literals
- 14.5.2 Simple names
- 14.5.2.1 Invariant meaning in blocks
- 14.5.3 Parenthesized expressions
- 14.5.4 Member access
- 14.5.4.1 Identical simple names and type names
- 14.5.5 Invocation expressions
- 14.5.5.1 Method invocations
- 14.5.5.2 Delegate invocations
- 14.5.6 Element access
- 14.5.6.1 Array access
- 14.5.6.2 Indexer access
- 14.5.7 This access
- 14.5.8 Base access
- 14.5.9 Postfix increment and decrement operators
- 14.5.10 The new operator......................................................................................................................
- 14.5.10.1 Object creation expressions
- 14.5.10.2 Array creation expressions
- 14.5.10.3 Delegate creation expressions
- 14.5.11 The typeof operator
- 14.5.12 The sizeof operator...................................................................................................................
- 14.5.13 The checked and unchecked operators C# LANGUAGE SPECIFICATION
- 14.5.14 Default value expression
- 14.5.15 Anonymous methods................................................................................................................
- 14.5.15.1 Anonymous method signatures
- 14.5.15.2 Anonymous method blocks
- 14.5.15.3 Outer variables
- 14.5.15.4 Anonymous method evaluation
- 14.5.15.5 Implementation example
- 14.6 Unary expressions
- 14.6.1 Unary plus operator
- 14.6.2 Unary minus operator.................................................................................................................
- 14.6.3 Logical negation operator
- 14.6.4 Bitwise complement operator
- 14.6.5 Prefix increment and decrement operators
- 14.6.6 Cast expressions
- 14.7 Arithmetic operators
- 14.7.1 Multiplication operator...............................................................................................................
- 14.7.2 Division operator........................................................................................................................
- 14.7.3 Remainder operator
- 14.7.4 Addition operator
- 14.7.5 Subtraction operator
- 14.8 Shift operators
- 14.9 Relational and type-testing operators
- 14.9.1 Integer comparison operators
- 14.9.2 Floating-point comparison operators
- 14.9.3 Decimal comparison operators
- 14.9.4 Boolean equality operators
- 14.9.5 Enumeration comparison operators............................................................................................
- 14.9.6 Reference type equality operators
- 14.9.7 String equality operators
- 14.9.8 Delegate equality operators
- 14.9.9 Equality operators and null
- 14.9.10 is operator
- 14.9.11 as operator
- 14.10 Logical operators
- 14.10.1 Integer logical operators
- 14.10.2 Enumeration logical operators
- 14.10.3 Boolean logical operators
- 14.10.4 The bool? logical operators
- 14.11 Conditional logical operators
- 14.11.1 Boolean conditional logical operators
- 14.11.2 User-defined conditional logical operators
- 14.12 The null coalescing operator
- 14.13 Conditional operator
- 14.14 Assignment operators
- 14.14.1 Simple assignment
- 14.14.2 Compound assignment
- 14.14.3 Event assignment
- 14.15 Expression
- 14.16 Constant expressions
- 14.17 Boolean expressions
- Statements
- 15.1 End points and reachability
- 15.2 Blocks
- 15.2.1 Statement lists Table of Contents
- 15.3 The empty statement
- 15.4 Labeled statements
- 15.5 Declaration statements
- 15.5.1 Local variable declarations
- 15.5.2 Local constant declarations
- 15.6 Expression statements
- 15.7 Selection statements
- 15.7.1 The if statement
- 15.7.2 The switch statement
- 15.8 Iteration statements
- 15.8.1 The while statement
- 15.8.2 The do statement
- 15.8.3 The for statement
- 15.8.4 The foreach statement
- 15.9 Jump statements
- 15.9.1 The break statement
- 15.9.2 The continue statement
- 15.9.3 The goto statement
- 15.9.4 The return statement...................................................................................................................
- 15.9.5 The throw statement
- 15.10 The try statement
- 15.11 The checked and unchecked statements
- 15.12 The lock statement
- 15.13 The using statement
- 15.14 The yield statement
- Namespaces
- 16.1 Compilation units
- 16.2 Namespace declarations
- 16.3 Extern alias directives
- 16.4 Using directives
- 16.4.1 Using alias directives
- 16.4.2 Using namespace directives
- 16.5 Namespace members
- 16.6 Type declarations
- 16.7 Qualified alias member
- Classes
- 17.1 Class declarations
- 17.1.1 Class modifiers
- 17.1.1.1 Abstract classes
- 17.1.1.2 Sealed classes
- 17.1.1.3 Static classes........................................................................................................................
- 17.1.2 Class base specification..............................................................................................................
- 17.1.2.1 Base classes
- 17.1.2.2 Interface implementations
- 17.1.3 Class body
- 17.1.4 Partial declarations
- 17.2 Class members...................................................................................................................................
- 17.2.1 Inheritance
- 17.2.2 The new modifier
- 17.2.3 Access modifiers
- 17.2.4 Constituent types
- 17.2.5 Static and instance members
- 17.2.6 Nested types C# LANGUAGE SPECIFICATION
- 17.2.6.1 Fully qualified name
- 17.2.6.2 Declared accessibility..........................................................................................................
- 17.2.6.3 Hiding..................................................................................................................................
- 17.2.6.4 this access
- 17.2.6.5 Access to private and protected members of the containing type
- 17.2.7 Reserved member names............................................................................................................
- 17.2.7.1 Member names reserved for properties
- 17.2.7.2 Member names reserved for events
- 17.2.7.3 Member names reserved for indexers
- 17.2.7.4 Member names reserved for finalizers
- 17.3 Constants
- 17.4 Fields
- 17.4.1 Static and instance fields
- 17.4.2 Readonly fields
- 17.4.2.1 Using static readonly fields for constants............................................................................
- 17.4.2.2 Versioning of constants and static readonly fields
- 17.4.3 Volatile fields
- 17.4.4 Field initialization
- 17.4.5 Variable initializers
- 17.4.5.1 Static field initialization
- 17.4.5.2 Instance field initialization
- 17.5 Methods
- 17.5.1 Method parameters
- 17.5.1.1 Value parameters
- 17.5.1.2 Reference parameters
- 17.5.1.3 Output parameters
- 17.5.1.4 Parameter arrays
- 17.5.2 Static and instance methods
- 17.5.3 Virtual methods
- 17.5.4 Override methods
- 17.5.5 Sealed methods
- 17.5.6 Abstract methods........................................................................................................................
- 17.5.7 External methods........................................................................................................................
- 17.5.8 Method body
- 17.5.9 Method overloading
- 17.6 Properties...........................................................................................................................................
- 17.6.1 Static and instance properties
- 17.6.2 Accessors
- 17.6.3 Virtual, sealed, override, and abstract accessors
- 17.7 Events
- 17.7.1 Field-like events
- 17.7.2 Event accessors
- 17.7.3 Static and instance events...........................................................................................................
- 17.7.4 Virtual, sealed, override, and abstract accessors
- 17.8 Indexers
- 17.8.1 Indexer overloading
- 17.9 Operators
- 17.9.1 Unary operators
- 17.9.2 Binary operators
- 17.9.3 Conversion operators
- 17.10 Instance constructors
- 17.10.1 Constructor initializers
- 17.10.2 Instance variable initializers
- 17.10.3 Constructor execution
- 17.10.4 Default constructors Table of Contents
- 17.10.5 Private constructors
- 17.10.6 Optional instance constructor parameters
- 17.11 Static constructors
- 17.12 Finalizers
- Structs
- 18.1 Struct declarations
- 18.1.1 Struct modifiers
- 18.1.2 Struct interfaces..........................................................................................................................
- 18.1.3 Struct body
- 18.2 Struct members
- 18.3 Class and struct differences
- 18.3.1 Value semantics
- 18.3.2 Inheritance
- 18.3.3 Assignment.................................................................................................................................
- 18.3.4 Default values
- 18.3.5 Boxing and unboxing
- 18.3.6 Meaning of this
- 18.3.7 Field initializers..........................................................................................................................
- 18.3.8 Constructors
- 18.3.9 Finalizers
- 18.3.10 Static constructors
- Arrays
- 19.1 Array types
- 19.1.1 The System.Array type...............................................................................................................
- 19.2 Array creation
- 19.3 Array element access
- 19.4 Array members
- 19.5 Array covariance
- 19.6 Arrays and the generic IList interface
- 19.7 Array initializers
- Interfaces................................................................................................................................................
- 20.1 Interface declarations
- 20.1.1 Interface modifiers
- 20.1.2 Base interfaces
- 20.1.3 Interface body
- 20.2 Interface members
- 20.2.1 Interface methods
- 20.2.2 Interface properties
- 20.2.3 Interface events
- 20.2.4 Interface indexers
- 20.2.5 Interface member access
- 20.3 Fully qualified interface member names
- 20.4 Interface implementations
- 20.4.1 Explicit interface member implementations
- 20.4.2 Interface mapping
- 20.4.3 Interface implementation inheritance
- 20.4.4 Interface re-implementation
- 20.4.5 Abstract classes and interfaces
- Enums
- 21.1 Enum declarations
- 21.2 Enum modifiers
- 21.3 Enum members C# LANGUAGE SPECIFICATION
- 21.4 The System.Enum type
- 21.5 Enum values and operations
- Delegates.................................................................................................................................................
- 22.1 Delegate declarations
- 22.2 Delegate instantiation
- 22.3 Delegate invocation
- Exceptions
- 23.1 Causes of exceptions
- 23.2 The System.Exception class
- 23.3 How exceptions are handled..............................................................................................................
- 23.4 Common exception classes
- Attributes
- 24.1 Attribute classes
- 24.1.1 Attribute usage
- 24.1.2 Positional and named parameters
- 24.1.3 Attribute parameter types
- 24.2 Attribute specification
- 24.3 Attribute instances
- 24.3.1 Compilation of an attribute
- 24.3.2 Run-time retrieval of an attribute instance
- 24.4 Reserved attributes
- 24.4.1 The AttributeUsage attribute
- 24.4.2 The Conditional attribute
- 24.4.2.1 Conditional methods
- 24.4.2.2 Conditional attribute classes................................................................................................
- 24.4.3 The Obsolete attribute
- Generics..................................................................................................................................................
- 25.1 Generic class declarations
- 25.1.1 Type parameters
- 25.1.2 The instance type
- 25.1.3 Members of generic classes
- 25.1.4 Static fields in generic classes
- 25.1.5 Static constructors in generic classes
- 25.1.6 Accessing protected members
- 25.1.7 Overloading in generic classes
- 25.1.8 Parameter array methods and type parameters
- 25.1.9 Overriding and generic classes...................................................................................................
- 25.1.10 Operators in generic classes
- 25.1.11 Nested types in generic classes
- 25.2 Generic struct declarations
- 25.3 Generic interface declarations
- 25.3.1 Uniqueness of implemented interfaces
- 25.3.2 Explicit interface member implementations
- 25.4 Generic delegate declarations............................................................................................................
- 25.5 Constructed types
- 25.5.1 Type arguments
- 25.5.2 Open and closed types
- 25.5.3 Base classes and interfaces of a constructed type
- 25.5.4 Members of a constructed type
- 25.5.5 Accessibility of a constructed type
- 25.5.6 Conversions
- 25.5.7 Using alias directives Table of Contents
- 25.6 Generic methods
- 25.6.1 Generic method signatures
- 25.6.2 Virtual generic methods
- 25.6.3 Calling generic methods.............................................................................................................
- 25.6.4 Inference of type arguments
- 25.6.5 Using a generic method with a delegate.....................................................................................
- 25.6.6 No generic properties, events, indexers, operators, constructors, or finalizers
- 25.7 Constraints.........................................................................................................................................
- 25.7.1 Satisfying constraints
- 25.7.2 Member lookup on type parameters
- 25.7.3 Type parameters and boxing
- 25.7.4 Conversions involving type parameters
- Iterators..................................................................................................................................................
- 26.1 Iterator blocks....................................................................................................................................
- 26.1.1 Enumerator interfaces
- 26.1.2 Enumerable interfaces
- 26.1.3 Yield type
- 26.1.4 This access
- 26.2 Enumerator objects
- 26.2.1 The MoveNext method
- 26.2.2 The Current property
- 26.2.3 The Dispose method...................................................................................................................
- 26.3 Enumerable objects
- 26.3.1 The GetEnumerator method
- 26.4 Implementation example
- Unsafe code
- 27.1 Unsafe contexts
- 27.2 Pointer types
- 27.3 Fixed and moveable variables
- 27.4 Pointer conversions
- 27.5 Pointers in expressions
- 27.5.1 Pointer indirection
- 27.5.2 Pointer member access
- 27.5.3 Pointer element access
- 27.5.4 The address-of operator..............................................................................................................
- 27.5.5 Pointer increment and decrement
- 27.5.6 Pointer arithmetic
- 27.5.7 Pointer comparison
- 27.5.8 The sizeof operator.....................................................................................................................
- 27.6 The fixed statement
- 27.7 Stack allocation
- 27.8 Dynamic memory allocation
- Annex A. Grammar
- A.1 Lexical grammar.................................................................................................................................
- A.1.1 Line terminators
- A.1.2 White space
- A.1.3 Comments
- A.1.4 Tokens
- A.1.5 Unicode escape sequences
- A.1.6 Identifiers
- A.1.7 Keywords
- A.1.8 Literals.........................................................................................................................................
- A.1.9 Operators and punctuators C# LANGUAGE SPECIFICATION
- A.1.10 Pre-processing directives...........................................................................................................
- A.2 Syntactic grammar
- A.2.1 Basic concepts
- A.2.2 Types
- A.2.3 Variables
- A.2.4 Expressions
- A.2.5 Statements
- A.2.6 Classes
- A.2.7 Structs..........................................................................................................................................
- A.2.8 Arrays
- A.2.9 Interfaces
- A.2.10 Enums
- A.2.11 Delegates
- A.2.12 Attributes
- A.2.13 Generics.....................................................................................................................................
- A.3 Grammar extensions for unsafe code
- Annex B. Portability issues
- B.1 Undefined behavior
- B.2 Implementation-defined behavior.......................................................................................................
- B.3 Unspecified behavior
- B.4 Other Issues
- Annex C. Naming guidelines
- Annex D. Standard Library
- Annex E. Documentation Comments
- E.1 Introduction.........................................................................................................................................
- E.2 Recommended tags
- E.2.1
- E.2.2
- E.2.3
- E.2.4
- E.2.5
- E.2.6
- E.2.7
- E.2.8
- E.2.9
- E.2.10
- E.2.11 ....................................................................................................................................
- E.2.12 ..........................................................................................................................................
- E.2.13
- E.2.14
- E.2.15
- E.2.16
- E.2.17
- E.3 Processing the documentation file
- E.3.1 ID string format
- E.3.2 ID string examples
- E.4 An example
- E.4.1 C# source code.............................................................................................................................
- E.4.2 Resulting XML
- Annex F. Bibliography
Table of Contents
xv
Annex G. Index ............................................................................................................................................ 508
Foreword
xvii
Foreword
This fourth edition cancels and replaces the third edition. Changes from the previous edition were made to align this Standard with ISO/IEC 23270:2006.