C# Standard.pdf

(2458 KB) Pobierz
C# Language Specification
Final draft – October 2002
Produced by ECMA TC39/TG2
1
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.
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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
v
Zgłoś jeśli naruszono regulamin