C# Language Specification 5.0

C# Language Specification 5.0

Microsoft

This book provides a complete description of the C# language 5.0.

  • Published on Dec 13 2013
  • Pages 527
  • Downloaded 10.8k
  • Type PDF
    • Like
    • Love It
    • Awesome
    • Interesting
    • It's Okay
    • Thumbs Down
  • 29k
  • 0

This book provides a complete description of the C# language 5.0.

Table of Contents

  1. Introduction

       1.1 Hello world
       1.2 Program structure
       1.3 Types and variables
       1.4 Expressions
       1.5 Statements
       1.6 Classes and objects
       1.6.1 Members
       1.6.2 Accessibility
       1.6.3 Type parameters
       1.6.4 Base classes
       1.6.5 Fields
       1.6.6 Methods
       1.6.6.1 Parameters
       1.6.6.2 Method body and local variables
       1.6.6.3 Static and instance methods
       1.6.6.4 Virtual, override, and abstract methods
       1.6.6.5 Method overloading
       1.6.7 Other function members
       1.6.7.1 Constructors
       1.6.7.2 Properties
       1.6.7.3 Indexers
       1.6.7.4 Events
       1.6.7.5 Operators
       1.6.7.6 Destructors
       1.7 Structs
       1.8 Arrays
       1.9 Interfaces
       1.10 Enums
       1.11 Delegates
       1.12 Attributes

  2. Lexical structure

       2.1 Programs
       2.2 Grammars
       2.2.1 Grammar notation
       2.2.2 Lexical grammar
       2.2.3 Syntactic grammar
       2.3 Lexical analysis
       2.3.1 Line terminators
       2.3.2 Comments
       2.3.3 White space
       2.4 Tokens
       2.4.1 Unicode character escape sequences
       2.4.2 Identifiers
       2.4.3 Keywords
       2.4.4 Literals
       2.4.4.1 Boolean literals
       2.4.4.2 Integer literals
       2.4.4.3 Real literals
       2.4.4.4 Character literals
       2.4.4.5 String literals
       2.4.4.6 The null literal
       2.4.5 Operators and punctuators
       2.5 Pre-processing directives
       2.5.1 Conditional compilation symbols
       2.5.2 Pre-processing expressions
       2.5.3 Declaration directives
       2.5.4 Conditional compilation directives
       2.5.5 Diagnostic directives
       2.5.6 Region directives
       2.5.7 Line directives
       2.5.8 Pragma directives
       2.5.8.1 Pragma warning
     
  3. Basic concepts

       3.1 Application Startup
       3.2 Application termination
       3.3 Declarations
       3.4 Members
       3.4.1 Namespace members
       3.4.2 Struct members
       3.4.3 Enumeration members
       3.4.4 Class members
       3.4.5 Interface members
       3.4.6 Array members
       3.4.7 Delegate members
       3.5 Member access
       3.5.1 Declared accessibility
       3.5.2 Accessibility domains
       3.5.3 Protected access for instance members
       3.5.4 Accessibility constraints
       3.6 Signatures and overloading
       3.7 Scopes
       3.7.1 Name hiding
       3.7.1.1 Hiding through nesting
       3.7.1.2 Hiding through inheritance
       3.8 Namespace and type names
       3.8.1 Fully qualified names
       3.9 Automatic memory management
       3.10 Execution order
     
  4. Types

       4.1 Value types
       4.1.1 The System.ValueType type
       4.1.2 Default constructors
       4.1.3 Struct types
       4.1.4 Simple types
       4.1.5 Integral types
       4.1.6 Floating point types
       4.1.7 The decimal type
       4.1.8 The bool type
       4.1.9 Enumeration types
       4.1.10 Nullable types
       4.2 Reference types
       4.2.1 Class types
       4.2.2 The object type
       4.2.3 The dynamic type
       4.2.4 The string type
       4.2.5 Interface types
       4.2.6 Array types
       4.2.7 Delegate types
       4.3 Boxing and unboxing
       4.3.1 Boxing conversions
       4.3.2 Unboxing conversions
       4.4 Constructed types
       4.4.1 Type arguments
       4.4.2 Open and closed types
       4.4.3 Bound and unbound types
       4.4.4 Satisfying constraints
       4.5 Type parameters
       4.6 Expression tree types
       4.7 The dynamic type
     
  5. Variables

       5.1 Variable categories
       5.1.1 Static variables
       5.1.2 Instance variables
       5.1.2.1 Instance variables in classes
       5.1.2.2 Instance variables in structs
       5.1.3 Array elements
       5.1.4 Value parameters
       5.1.5 Reference parameters
       5.1.6 Output parameters
       5.1.7 Local variables
       5.2 Default values
       5.3 Definite assignment
       5.3.1 Initially assigned variables
       5.3.2 Initially unassigned variables
       5.3.3 Precise rules for determining definite assignment
       5.3.3.1 General rules for statements
       5.3.3.2 Block statements, checked, and unchecked statements
       5.3.3.3 Expression statements
       5.3.3.4 Declaration statements
       5.3.3.5 If statements
       5.3.3.6 Switch statements
       5.3.3.7 While statements
       5.3.3.8 Do statements
       5.3.3.9 For statements
       5.3.3.10 Break, continue, and goto statements
       5.3.3.11 Throw statements
       5.3.3.12 Return statements
       5.3.3.13 Try-catch statements
       5.3.3.14 Try-finally statements
       5.3.3.15 Try-catch-finally statements
       5.3.3.16 Foreach statements
       5.3.3.17 Using statements
       5.3.3.18 Lock statements
       5.3.3.19 Yield statements
       5.3.3.20 General rules for simple expressions
       5.3.3.21 General rules for expressions with embedded expressions
       5.3.3.22 Invocation expressions and object creation expressions
       5.3.3.23 Simple assignment expressions
       5.3.3.24 && expressions
       5.3.3.25 || expressions
       5.3.3.26 ! expressions
       5.3.3.27 ?? expressions
       5.3.3.28 ?: expressions
       5.3.3.29 Anonymous functions
       5.4 Variable references
       5.5 Atomicity of variable references

  6. Conversions

       6.1 Implicit conversions
       6.1.1 Identity conversion
       6.1.2 Implicit numeric conversions
       6.1.3 Implicit enumeration conversions
       6.1.4 Implicit nullable conversions
       6.1.5 Null literal conversions
       6.1.6 Implicit reference conversions
       6.1.7 Boxing conversions
       6.1.8 Implicit dynamic conversions
       6.1.9 Implicit constant expression conversions
       6.1.10 Implicit conversions involving type parameters
       6.1.11 User-defined implicit conversions
       6.1.12 Anonymous function conversions and method group conversions
       6.2 Explicit conversions
       6.2.1 Explicit numeric conversions
       6.2.2 Explicit enumeration conversions
       6.2.3 Explicit nullable conversions
       6.2.4 Explicit reference conversions
       6.2.5 Unboxing conversions
       6.2.6 Explicit dynamic conversions
       6.2.7 Explicit conversions involving type parameters
       6.2.8 User-defined explicit conversions
       6.3 Standard conversions
       6.3.1 Standard implicit conversions
       6.3.2 Standard explicit conversions
       6.4 User-defined conversions
       6.4.1 Permitted user-defined conversions
       6.4.2 Lifted conversion operators
       6.4.3 Evaluation of user-defined conversions
       6.4.4 User-defined implicit conversions
       6.4.5 User-defined explicit conversions
       6.5 Anonymous function conversions
       6.5.1 Evaluation of anonymous function conversions to delegate types
       6.5.2 Evaluation of anonymous function conversions to expression tree types   
       6.5.3 Implementation example
       6.6 Method group conversions

  7. Expressions

       7.1 Expression classifications
       7.1.1 Values of expressions
       7.2 Static and Dynamic Binding
       7.2.1 Binding-time
       7.2.2 Dynamic binding
       7.2.3 Types of constituent expressions
       7.3 Operators
       7.3.1 Operator precedence and associativity
       7.3.2 Operator overloading
       7.3.3 Unary operator overload resolution
       7.3.4 Binary operator overload resolution
       7.3.5 Candidate user-defined operators
       7.3.6 Numeric promotions
       7.3.6.1 Unary numeric promotions
       7.3.6.2 Binary numeric promotions
       7.3.7 Lifted operators
       7.4 Member lookup
       7.4.1 Base types
       7.5 Function members
       7.5.1 Argument lists
       7.5.1.1 Corresponding parameters
       7.5.1.2 Run-time evaluation of argument lists
       7.5.2 Type inference
       7.5.2.1 The first phase
       7.5.2.2 The second phase
       7.5.2.3 Input types
       7.5.2.4 Output types
       7.5.2.5 Dependence
       7.5.2.6 Output type inferences
       7.5.2.7 Explicit parameter type inferences
       7.5.2.8 Exact inferences
       7.5.2.9 Lower-bound inferences
       7.5.2.10 Upper-bound inferences
       7.5.2.11 Fixing
       7.5.2.12 Inferred return type
       7.5.2.13 Type inference for conversion of method groups
       7.5.2.14 Finding the best common type of a set of expressions
       7.5.3 Overload resolution
       7.5.3.1 Applicable function member
       7.5.3.2 Better function member
       7.5.3.3 Better conversion from expression
       7.5.3.4 Better conversion from type
       7.5.3.5 Better conversion target
       7.5.3.6 Overloading in generic classes
       7.5.4 Compile-time checking of dynamic overload resolution
       7.5.5 Function member invocation
       7.5.5.1 Invocations on boxed instances
       7.6 Primary expressions
       7.6.1 Literals
       7.6.2 Simple names
       7.6.2.1 Invariant meaning in blocks
       7.6.3 Parenthesized expressions
       7.6.4 Member access
       7.6.4.1 Identical simple names and type names
       7.6.4.2 Grammar ambiguities
       7.6.5 Invocation expressions
       7.6.5.1 Method invocations
       7.6.5.2 Extension method invocations
       7.6.5.3 Delegate invocations
       7.6.6 Element access
       7.6.6.1 Array access
       7.6.6.2 Indexer access
       7.6.7 This access
       7.6.8 Base access
       7.6.9 Postfix increment and decrement operators
       7.6.10 The new operator
       7.6.10.1 Object creation expressions
       7.6.10.2 Object initializers
       7.6.10.3 Collection initializers
       7.6.10.4 Array creation expressions
       7.6.10.5 Delegate creation expressions
       7.6.10.6 Anonymous object creation expressions
       7.6.11 The typeof operator
       7.6.12 The checked and unchecked operators
       7.6.13 Default value expressions
       7.6.14 Anonymous method expressions
       7.7 Unary operators
       7.7.1 Unary plus operator
       7.7.2 Unary minus operator
       7.7.3 Logical negation operator
       7.7.4 Bitwise complement operator
       7.7.5 Prefix increment and decrement operators
       7.7.6 Cast expressions
       7.8 Arithmetic operators
       7.8.1 Multiplication operator
       7.8.2 Division operator
       7.8.3 Remainder operator
       7.8.4 Addition operator
       7.8.5 Subtraction operator
       7.9 Shift operators
       7.10 Relational and type-testing operators
       7.10.1 Integer comparison operators
       7.10.2 Floating-point comparison operators
       7.10.3 Decimal comparison operators
       7.10.4 Boolean equality operators
       7.10.5 Enumeration comparison operators
       7.10.6 Reference type equality operators
       7.10.7 String equality operators
       7.10.8 Delegate equality operators
       7.10.9 Equality operators and null
       7.10.10 The is operator
       7.10.11 The as operator
       7.11 Logical operators
       7.11.1 Integer logical operators
       7.11.2 Enumeration logical operators
       7.11.3 Boolean logical operators
       7.11.4 Nullable boolean logical operators
       7.12 Conditional logical operators
       7.12.1 Boolean conditional logical operators
       7.12.2 User-defined conditional logical operators
       7.13 The null coalescing operator
       7.14 Conditional operator
       7.15 Anonymous function expressions
       7.15.1 Anonymous function signatures
       7.15.2 Anonymous function bodies
       7.15.3 Overload resolution
       7.15.4 Anonymous functions and dynamic binding
       7.15.5 Outer variables
       7.15.5.1 Captured outer variables
       7.15.5.2 Instantiation of local variables
       7.15.6 Evaluation of anonymous function expressions
       7.16 Query expressions
       7.16.1 Ambiguities in query expressions
       7.16.2 Query expression translation
       7.16.2.1 Select and groupby clauses with continuations
       7.16.2.2 Explicit range variable types
       7.16.2.3 Degenerate query expressions
       7.16.2.4 From, let, where, join and orderby clauses
       7.16.2.5 Select clauses
       7.16.2.6 Groupby clauses
       7.16.2.7 Transparent identifiers
       7.16.3 The query expression pattern
       7.17 Assignment operators
       7.17.1 Simple assignment
       7.17.2 Compound assignment
       7.17.3 Event assignment
       7.18 Expression
       7.19 Constant expressions
       7.20 Boolean expressions

  8. Statements

        8.1 End points and reachability
        8.2 Blocks
        8.2.1 Statement lists
        8.3 The empty statement
        8.4 Labeled statements
        8.5 Declaration statements
        8.5.1 Local variable declarations
        8.5.2 Local constant declarations
        8.6 Expression statements
        8.7 Selection statements
        8.7.1 The if statement
        8.7.2 The switch statement
        8.8 Iteration statements
        8.8.1 The while statement
        8.8.2 The do statement
        8.8.3 The for statement
        8.8.4 The foreach statement
        8.9 Jump statements
        8.9.1 The break statement
        8.9.2 The continue statement
        8.9.3 The goto statement
        8.9.4 The return statement
        8.9.5 The throw statement
        8.10 The try statement
        8.11 The checked and unchecked statements
        8.12 The lock statement
        8.13 The using statement
        8.14 The yield statement

  9. Namespaces

        9.1 Compilation units
        9.2 Namespace declarations
        9.3 Extern aliases
        9.4 Using directives
        9.4.1 Using alias directives
        9.4.2 Using namespace directives
        9.5 Namespace members
        9.6 Type declarations
        9.7 Namespace alias qualifiers
        9.7.1 Uniqueness of aliases

  10. Classes

        10.1 Class declarations
        10.1.1 Class modifiers
        10.1.1.1 Abstract classes
        10.1.1.2 Sealed classes
        10.1.1.3 Static classes
        10.1.2 Partial modifier
        10.1.3 Type parameters
        10.1.4 Class base specification
        10.1.4.1 Base classes
        10.1.4.2 Interface implementations
        10.1.5 Type parameter constraints
        10.1.6 Class body
        10.2 Partial types
        10.2.1 Attributes
        10.2.2 Modifiers
        10.2.3 Type parameters and constraints
        10.2.4 Base class
        10.2.5 Base interfaces
        10.2.6 Members
        10.2.7 Partial methods
        10.2.8 Name binding
        10.3 Class members
        10.3.1 The instance type
        10.3.2 Members of constructed types
        10.3.3 Inheritance
        10.3.4 The new modifier
        10.3.5 Access modifiers
        10.3.6 Constituent types
        10.3.7 Static and instance members
        10.3.8 Nested types
        10.3.8.1 Fully qualified name
        10.3.8.2 Declared accessibility
        10.3.8.3 Hiding
        10.3.8.4 this access
        10.3.8.5 Access to private and protected members of the containing type
        10.3.8.6 Nested types in generic classes
        10.3.9 Reserved member names
        10.3.9.1 Member names reserved for properties
        10.3.9.2 Member names reserved for events
        10.3.9.3 Member names reserved for indexers
        10.3.9.4 Member names reserved for destructors
        10.4 Constants
        10.5 Fields
        10.5.1 Static and instance fields
        10.5.2 Readonly fields
        10.5.2.1 Using static readonly fields for constants
        10.5.2.2 Versioning of constants and static readonly fields
        10.5.3 Volatile fields
        10.5.4 Field initialization
        10.5.5 Variable initializers
        10.5.5.1 Static field initialization
        10.5.5.2 Instance field initialization
        10.6 Methods
        10.6.1 Method parameters
        10.6.1.1 Value parameters
        10.6.1.2 Reference parameters
        10.6.1.3 Output parameters
        10.6.1.4 Parameter arrays
        10.6.2 Static and instance methods
        10.6.3 Virtual methods
        10.6.4 Override methods
        10.6.5 Sealed methods
        10.6.6 Abstract methods
        10.6.7 External methods
        10.6.8 Partial methods
        10.6.9 Extension methods
        10.6.10 Method body
        10.6.11 Method overloading
        10.7 Properties
        10.7.1 Static and instance properties
        10.7.2 Accessors
        10.7.3 Automatically implemented properties
        10.7.4 Accessibility
        10.7.5 Virtual, sealed, override, and abstract accessors
        10.8 Events
        10.8.1 Field-like events
        10.8.2 Event accessors
        10.8.3 Static and instance events
        10.8.4 Virtual, sealed, override, and abstract accessors
        10.9 Indexers
        10.9.1 Indexer overloading
        10.10 Operators
        10.10.1 Unary operators
        10.10.2 Binary operators
        10.10.3 Conversion operators
        10.11 Instance constructors
        10.11.1 Constructor initializers
        10.11.2 Instance variable initializers
        10.11.3 Constructor execution
        10.11.4 Default constructors
        10.11.5 Private constructors
        10.11.6 Optional instance constructor parameters
        10.12 Static constructors
        10.13 Destructors
        10.14 Iterators
        10.14.1 Enumerator interfaces
        10.14.2 Enumerable interfaces
        10.14.3 Yield type
        10.14.4 Enumerator objects
        10.14.4.1 The MoveNext method
        10.14.4.2 The Current property
        10.14.4.3 The Dispose method
        10.14.5 Enumerable objects
        10.14.5.1 The GetEnumerator method
        10.14.6 Implementation example

  11. Structs

        11.1 Struct declarations
        11.1.1 Struct modifiers
        11.1.2 Partial modifier
        11.1.3 Struct interfaces
        11.1.4 Struct body
        11.2 Struct members
        11.3 Class and struct differences
        11.3.1 Value semantics
        11.3.2 Inheritance
        11.3.3 Assignment
        11.3.4 Default values
        11.3.5 Boxing and unboxing
        11.3.6 Meaning of this
        11.3.7 Field initializers
        11.3.8 Constructors
        11.3.9 Destructors
        11.3.10 Static constructors
        11.4 Struct examples
        11.4.1 Database integer type
        11.4.2 Database boolean type

  12. Arrays

        12.1 Array types
        12.1.1 The System.Array type
        12.1.2 Arrays and the generic IList interface
        12.2 Array creation
        12.3 Array element access
        12.4 Array members
        12.5 Array covariance
        12.6 Array initializers

  13. Interfaces

        13.1 Interface declarations
        13.1.1 Interface modifiers
        13.1.2 Partial modifier
        13.1.3 Variant type parameter lists
        13.1.3.1 Variance safety
        13.1.3.2 Variance conversion
        13.1.4 Base interfaces
        13.1.5 Interface body
        13.2 Interface members
        13.2.1 Interface methods
        13.2.2 Interface properties
        13.2.3 Interface events
        13.2.4 Interface indexers
        13.2.5 Interface member access
        13.3 Fully qualified interface member names
        13.4 Interface implementations
        13.4.1 Explicit interface member implementations
        13.4.2 Uniqueness of implemented interfaces
        13.4.3 Implementation of generic methods
        13.4.4 Interface mapping
        13.4.5 Interface implementation inheritance
        13.4.6 Interface re-implementation
        13.4.7 Abstract classes and interfaces

  14. Enums

        14.1 Enum declarations
        14.2 Enum modifiers
        14.3 Enum members
        14.4 The System.Enum type
        14.5 Enum values and operations

  15. Delegates

        15.1 Delegate declarations
        15.2 Delegate compatibility
        15.3 Delegate instantiation
        15.4 Delegate invocation

  16. Exceptions

        16.1 Causes of exceptions
        16.2 The System.Exception class
        16.3 How exceptions are handled
        16.4 Common Exception Classes

  17. Attributes

        17.1 Attribute classes
        17.1.1 Attribute usage
        17.1.2 Positional and named parameters
        17.1.3 Attribute parameter types
        17.2 Attribute specification
        17.3 Attribute instances
        17.3.1 Compilation of an attribute
        17.3.2 Run-time retrieval of an attribute instance
        17.4 Reserved attributes
        17.4.1 The AttributeUsage attribute
        17.4.2 The Conditional attribute
        17.4.2.1 Conditional methods
        17.4.2.2 Conditional attribute classes
        17.4.3 The Obsolete attribute
        17.5 Attributes for Interoperation
        17.5.1 Interoperation with COM and Win32 components
        17.5.2 Interoperation with other .NET languages
        17.5.2.1 The IndexerName attribute

  18. Unsafe code

        18.1 Unsafe contexts
        18.2 Pointer types
        18.3 Fixed and moveable variables
        18.4 Pointer conversions
        18.4.1 Pointer arrays
        18.5 Pointers in expressions
        18.5.1 Pointer indirection
        18.5.2 Pointer member access
        18.5.3 Pointer element access
        18.5.4 The address-of operator
        18.5.5 Pointer increment and decrement
        18.5.6 Pointer arithmetic
        18.5.7 Pointer comparison
        18.5.8 The sizeof operator
        18.6 The fixed statement
        18.7 Fixed size buffers
        18.7.1 Fixed size buffer declarations
        18.7.2 Fixed size buffers in expressions
        18.7.3 Definite assignment checking
        18.8 Stack allocation
        18.9 Dynamic memory allocation

    A. Documentation comments

        A.1 Introduction
        A.2 Recommended tags
        A.2.1 <c>
        A.2.2 <code>
        A.2.3 <example>
        A.2.4 <exception>
        A.2.5 <include>
        A.2.6 <list>
        A.2.7 <para>
        A.2.8 <param>
        A.2.9 <paramref>
        A.2.10 <permission>
        A.2.11 <remark>
        A.2.12 <returns>
        A.2.13 <see>
        A.2.14 <seealso>
        A.2.15 <summary>
        A.2.16 <value>
        A.2.17 <typeparam>
        A.2.18 <typeparamref>
        A.3 Processing the documentation file
        A.3.1 ID string format
        A.3.2 ID string examples
        A.4 An example
        A.4.1 C# source code
        A.4.2 Resulting XML

    B. Grammar

        B.1 Lexical grammar
        B.1.1 Line terminators
        B.1.2 Comments
        B.1.3 White space
        B.1.4 Tokens
        B.1.5 Unicode character escape sequences
        B.1.6 Identifiers
        B.1.7 Keywords
        B.1.8 Literals
        B.1.9 Operators and punctuators
        B.1.10 Pre-processing directives
        B.2 Syntactic grammar
        B.2.1 Basic concepts
        B.2.2 Types
        B.2.3 Variables
        B.2.4 Expressions
        B.2.5 Statements
        B.2.6 Namespaces
        B.2.7 Classes
        B.2.8 Structs
        B.2.9 Arrays
        B.2.10 Interfaces
        B.2.11 Enums
        B.2.12 Delegates
        B.2.13 Attributes
        B.3 Grammar extensions for unsafe code

    C. References

Image Loading...