C# Language Specification
Final draft – October 2002
Produced by ECMA TC39/TG2
Brief history
This International Standard is based on a submission from Hewlett-Packard, Intel, and Microsoft, that describes a language called C#, which was developed within Microsoft. The principal inventors of this language were Anders Hejlsberg, Scott Wiltamuth, and Peter Golde. The first widely distributed implementation of C# was released by Microsoft in July 2000, as part of its .NET Framework initiative.
ECMA Technical Committee 39 (TC39) Task Group 2 (TG2) was formed in September 2000, to produce a standard for C#. Another Task Group, TG3, was also formed at that time to produce a standard for a library and execution environment called Common Language Infrastructure (CLI). (CLI is based on a subset of the .NET Framework.) Although Microsoft’s implementation of C# relies on CLI for library and runtime support, other implementations of C# need not, provided they support an alternate way of getting at the minimum CLI features required by this C# standard.
As the definition of C# evolved, the goals used in its design were as follows:
· C# is intended to be a simple, modern, general-purpose, object-oriented programming language.
· The language, and implementations thereof, should provide support for software engineering principles such as strong type checking, array bounds checking, detection of attempts to use uninitialized variables, and automatic garbage collection. Software robustness, durability, and programmer productivity are important.
· The language is intended for use in developing software components suitable for deployment in distributed environments.
· Source code portability is very important, as is programmer portability, especially for those programmers already familiar with C and C++.
· Support for internationalization is very important.
· C# is intended to be suitable for writing applications for both hosted and embedded systems, ranging from the very large that use sophisticated operating systems, down to the very small having dedicated functions.
· Although C# applications are intended to be economical with regards to memory and processing power requirements, the language was not intended to compete directly on performance and size with C or assembly language.
The development of this standard started in November 2000.
It is expected there will be future revisions to this standard, primarily to add new functionality.
iii
Table of Contents
1. Scope 1
2. Conformance 3
3. References 5
4. Definitions 7
5. Notational conventions 9
6. Acronyms and abbreviations 11
7. General description 13
8. Language Overview 15
8.1 Getting started 15
8.2 Types 16
8.2.1 Predefined types 17
8.2.2 Conversions 19
8.2.3 Array types 20
8.2.4 Type system unification 21
8.3 Variables and parameters 22
8.4 Automatic memory management 25
8.5 Expressions 27
8.6 Statements 28
8.7 Classes 31
8.7.1 Constants 32
8.7.2 Fields 33
8.7.3 Methods 34
8.7.4 Properties 35
8.7.5 Events 36
8.7.6 Operators 37
8.7.7 Indexers 38
8.7.8 Instance constructors 39
8.7.9 Destructors 39
8.7.10 Static constructors 40
8.7.11 Inheritance 40
8.8 Structs 41
8.9 Interfaces 42
8.10 Delegates 43
8.11 Enums 44
8.12 Namespaces and assemblies 45
8.13 Versioning 46
8.14 Attributes 48
9. Lexical structure 51
9.1 Programs 51
9.2 Grammars 51
9.2.1 Lexical grammar 51
9.2.2 Syntactic grammar 51
9.3 Lexical analysis 52
9.3.1 Line terminators 52
9.3.2 Comments 53
9.3.3 White space 54
9.4 Tokens 54
9.4.1 Unicode escape sequences 54
9.4.2 Identifiers 55
9.4.3 Keywords 56
9.4.4 Literals 57
9.4.5 Operators and punctuators 62
9.5 Pre-processing directives 62
9.5.1 Conditional compilation symbols 63
9.5.2 Pre-processing expressions 63
9.5.3 Declaration directives 64
9.5.4 Conditional compilation directives 65
9.5.5 Diagnostic directives 67
9.5.6 Region control 67
9.5.7 Line directives 68
10. Basic concepts 69
10.1 Application startup 69
10.2 Application termination 69
10.3 Declarations 70
10.4 Members 72
10.4.1 Namespace members 72
10.4.2 Struct members 72
10.4.3 Enumeration members 73
10.4.4 Class members 73
10.4.5 Interface members 73
10.4.6 Array members 73
10.4.7 Delegate members 73
10.5 Member access 73
10.5.1 Declared accessibility 74
10.5.2 Accessibility domains 74
10.5.3 Protected access for instance members 77
10.5.4 Accessibility constraints 77
10.6 Signatures and overloading 78
10.7 Scopes 79
10.7.1 Name hiding 81
10.8 Namespace and type names 83
10.8.1 Fully qualified names 84
10.9 Automatic memory management 85
10.10 Execution order 87
11. Types 89
11.1 Value types 89
11.1.1 Default constructors 90
11.1.2 Struct types 90
11.1.3 Simple types 91
11.1.4 Integral types 91
11.1.5 Floating point types 92
11.1.6 The decimal type 94
11.1.7 The bool type 94
11.1.8 Enumeration types 94
11.2 Reference types 94
11.2.1 Class types 95
11.2.2 The object type 95
11.2.3 The string type 95
11.2.4 Interface types 96
11.2.5 Array types 96
11.2.6 Delegate types 96
11.3 Boxing and unboxing 96
11.3.1 Boxing conversions 96
11.3.2 Unboxing conversions 97
...
g83