ECMA 334-2006 C# Language Specification《C# 语言规范》.pdf

上传人:李朗 文档编号:704765 上传时间:2019-01-03 格式:PDF 页数:554 大小:3.26MB
下载 相关 举报
ECMA 334-2006 C# Language Specification《C# 语言规范》.pdf_第1页
第1页 / 共554页
ECMA 334-2006 C# Language Specification《C# 语言规范》.pdf_第2页
第2页 / 共554页
ECMA 334-2006 C# Language Specification《C# 语言规范》.pdf_第3页
第3页 / 共554页
ECMA 334-2006 C# Language Specification《C# 语言规范》.pdf_第4页
第4页 / 共554页
ECMA 334-2006 C# Language Specification《C# 语言规范》.pdf_第5页
第5页 / 共554页
点击查看更多>>
资源描述

1、 ECMA-334 4thEdition / June 2006 C# Language Specification ECMA-334 4thEdition / June 2006 C# Language Specification Ecma International Rue du Rhne 114 CH-1204 Geneva T/F: +41 22 849 6000/01 www.ecma-international.org . Table of Contents Table of Contents Foreword xvii Introduction xix 1. Scope . 1

2、2. Conformance . 3 3. Normative 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

3、system unification . 22 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 33 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 constru

4、ctors 39 8.7.9 Finalizers 40 8.7.10 Static constructors 40 8.7.11 Inheritance 41 8.7.12 Static classes 42 8.7.13 Partial type declarations . 42 8.8 Structs 43 8.9 Interfaces . 44 8.10 Delegates . 45 8.11 Enums 46 8.12 Namespaces and assemblies 46 8.13 Versioning . 48 8.14 Extern aliases. 49 8.15 Att

5、ributes . 51 8.16 Generics . 52 iii C# LANGUAGE SPECIFICATION 8.16.1 Why generics? 52 8.16.2 Creating and consuming generics 53 8.16.3 Multiple type parameters 54 8.16.4 Constraints . 54 8.16.5 Generic methods 56 8.17 Anonymous methods . 56 8.18 Iterators . 59 8.19 Nullable types 62 9. Lexical struc

6、ture 65 9.1 Programs . 65 9.2 Grammars 65 9.2.1 Lexical grammar 65 9.2.2 Syntactic grammar . 65 9.2.3 Grammar ambiguities . 66 9.3 Lexical analysis . 66 9.3.1 Line terminators . 67 9.3.2 Comments 67 9.3.3 White space 69 9.4 Tokens . 69 9.4.1 Unicode escape sequences . 69 9.4.2 Identifiers . 70 9.4.3

7、 Keywords . 71 9.4.4 Literals . 72 9.4.4.1 Boolean literals 72 9.4.4.2 Integer literals 72 9.4.4.3 Real literals 73 9.4.4.4 Character literals . 74 9.4.4.5 String literals . 75 9.4.4.6 The null literal . 76 9.4.5 Operators and punctuators 77 9.5 Pre-processing directives . 77 9.5.1 Conditional compi

8、lation symbols 78 9.5.2 Pre-processing expressions 78 9.5.3 Declaration directives . 79 9.5.4 Conditional compilation directives 80 9.5.5 Diagnostic directives 82 9.5.6 Region control 83 9.5.7 Line directives 83 9.5.8 Pragma directives . 84 10. Basic concepts 85 10.1 Application startup 85 10.2 Appl

9、ication termination . 86 10.3 Declarations . 86 10.4 Members 89 10.4.1 Namespace members 89 10.4.2 Struct members 89 10.4.3 Enumeration members . 89 10.4.4 Class members . 89 10.4.5 Interface members 90 10.4.6 Array members . 90 10.4.7 Delegate members 90 10.5 Member access 90 10.5.1 Declared access

10、ibility. 90 iv Table of Contents 10.5.2 Accessibility domains 91 10.5.3 Protected access for instance members 93 10.5.4 Accessibility constraints . 94 10.6 Signatures and overloading . 95 10.7 Scopes . 96 10.7.1 Name hiding . 98 10.7.1.1 Hiding through nesting 98 10.7.1.2 Hiding through inheritance

11、99 10.8 Namespace and type names . 100 10.8.1 Unqualified name . 102 10.8.2 Fully qualified names . 102 10.9 Automatic memory management 103 10.10 Execution order . 105 11. Types 107 11.1 Value types 107 11.1.1 The System.ValueType type 108 11.1.2 Default constructors . 108 11.1.3 Struct types . 109

12、 11.1.4 Simple types . 109 11.1.5 Integral types 110 11.1.6 Floating point types 111 11.1.7 The decimal type 111 11.1.8 The bool type . 112 11.1.9 Enumeration types 112 11.2 Reference types . 112 11.2.1 Class types 113 11.2.2 The object type . 113 11.2.3 The string type . 113 11.2.4 Interface types

13、113 11.2.5 Array types . 114 11.2.6 Delegate types 114 11.2.7 The null type 114 11.3 Boxing and unboxing 114 11.3.1 Boxing conversions 114 11.3.2 Unboxing conversions 115 11.4 Nullable types 116 11.4.1 Members . 116 11.4.2 Implemented interfaces 117 12. Variables 119 12.1 Variable categories 119 12.

14、1.1 Static variables . 119 12.1.2 Instance variables . 119 12.1.2.1 Instance variables in classes 119 12.1.2.2 Instance variables in structs . 120 12.1.3 Array elements . 120 12.1.4 Value parameters 120 12.1.5 Reference parameters . 120 12.1.6 Output parameters 120 12.1.7 Local variables . 121 12.2

15、Default values 121 12.3 Definite assignment . 122 12.3.1 Initially assigned variables . 123 12.3.2 Initially unassigned variables . 123 v C# LANGUAGE SPECIFICATION 12.3.3 Precise rules for determining definite assignment . 123 12.3.3.1 General rules for statements 124 12.3.3.2 Block statements, chec

16、ked, and unchecked statements . 124 12.3.3.3 Expression statements . 124 12.3.3.4 Declaration statements 124 12.3.3.5 If statements 124 12.3.3.6 Switch statements 125 12.3.3.7 While statements . 125 12.3.3.8 Do statements 125 12.3.3.9 For statements . 125 12.3.3.10 Break, continue, and goto statemen

17、ts 126 12.3.3.11 Throw statements 126 12.3.3.12 Return statements 126 12.3.3.13 Try-catch statements . 126 12.3.3.14 Try-finally statements . 127 12.3.3.15 Try-catch-finally statements 127 12.3.3.16 Foreach statements 128 12.3.3.17 Using statements . 128 12.3.3.18 Lock statements . 128 12.3.3.19 Gen

18、eral rules for simple expressions 128 12.3.3.20 General rules for expressions with embedded expressions . 129 12.3.3.21 Invocation expressions and object creation expressions . 129 12.3.3.22 Simple assignment expressions . 129 12.3.3.23 The syntax and constraints of the C# language; The semantic rul

19、es for interpreting C# programs; The restrictions and limits imposed by a conforming implementation of C#. This International Standard does not specify The mechanism by which C# programs are transformed for use by a data-processing system; The mechanism by which C# applications are invoked for use b

20、y a data-processing system; The mechanism by which input data are transformed for use by a C# application; The mechanism by which output data are transformed after being produced by a C# application; The size or complexity of a program and its data that will exceed the capacity of any specific data-

21、processing system or the capacity of a particular processor; All minimal requirements of a data-processing system that is capable of supporting a conforming implementation. 2 3BConformance 2. Conformance Conformance is of interest to the following audiences: Those designing, implementing, or maintai

22、ning C# implementations. Governmental or commercial entities wishing to procure C# implementations. Testing organizations wishing to provide a C# conformance test suite. Programmers wishing to port code from one C# implementation to another. Educators wishing to teach Standard C#. Authors wanting to

23、 write about Standard C#. As such, conformance is most important, and the bulk of this International Standard is aimed at specifying the characteristics that make C# implementations and C# programs conforming ones. The text in this International Standard that specifies requirements is considered nor

24、mative. All other text in this specification is informative; that is, for information purposes only. Unless stated otherwise, all text is normative. Normative text is further broken into required and conditional categories. Conditionally normative text specifies a feature and its requirements where

25、the feature is optional. However, if that feature is provided, its syntax and semantics must be exactly as specified. Undefined behavior is indicated in this International Standard only by the words undefined behavior. A strictly conforming program shall use only those features of the language speci

26、fied in this International Standard as being required. (This means that a strictly conforming program cannot use any conditionally normative feature.) It shall not produce output dependent on any unspecified, undefined, or implementation-defined behavior. A conforming implementation of C# must accep

27、t any strictly conforming program. A conforming implementation of C# must provide and support all the types, values, objects, properties, methods, and program syntax and semantics described in the normative (but not the conditionally normative) parts in this International Standard. A conforming impl

28、ementation of C# shall interpret characters in conformance with the Unicode Standard, Version 4.0, and ISO/IEC 10646-1. Conforming implementations must accept Unicode source files encoded with the UTF-8 encoding form. A conforming implementation of C# shall not successfully translate source containi

29、ng a #error preprocessing directive unless it is part of a group skipped by conditional compilation. A conforming implementation of C# shall produce at least one diagnostic message if the source program violates any rule of syntax, or any negative requirement (defined as a “shall” or “shall not” or

30、“error” or “warning” requirement), unless that requirement is marked with the words “no diagnostic is required”. A conforming implementation of C# is permitted to provide additional types, values, objects, properties, and methods beyond those described in this International Standard, provided they d

31、o not alter the behavior of any strictly conforming program. Conforming implementations are required to diagnose programs that use extensions that are ill formed according to this International Standard. Having done so, however; they can compile and execute such programs. (The ability to have extens

32、ions implies that a conforming implementation reserves no identifiers other than those explicitly reserved in this International Standard.) 3 C# LANGUAGE SPECIFICATION 4 A conforming implementation of C# shall be accompanied by a document that defines all implementation-defined characteristics, and

33、all extensions. A conforming implementation of C# shall support the class library documented in Annex D. This library is included by reference in this International Standard. A conforming program is one that is acceptable to a conforming implementation. (Such a program is permitted to contain extens

34、ions or conditionally normative features.) 3 4BNormative references 3. Normative references The following normative documents contain provisions, which, through reference in this text, constitute provisions of this International Standard. For dated references, subsequent amendments to, or revisions

35、of, any of these publications do not apply. However, parties to agreements based on this International Standard are encouraged to investigate the possibility of applying the most recent editions of the normative documents indicated below. For undated references, the latest edition of the normative d

36、ocument referred to applies. Members of ISO and IEC maintain registers of currently valid International Standards. ISO/IEC 23271:2005, Common Language Infrastructure (CLI), Partition IV: Base Class Library (BCL), Extended Numerics Library, and Extended Array Library. ISO 31.11:1992, Quantities and u

37、nits Part 11: Mathematical signs and symbols for use in the physical sciences and technology. ISO/IEC 2382.1:1993, Information technology Vocabulary Part 1: Fundamental terms. ISO/IEC 10646 (all parts), Information technology Universal Multiple-Octet Coded Character Set (UCS). IEC 60559:1989, Binary

38、 floating-point arithmetic for microprocessor systems (previously designated IEC 559:1989). (This standard is widely known by its U.S. national designation, ANSI/IEEE Standard 754-1985, IEEE Standard for Binary Floating-Point Arithmetic.) The Unicode Consortium. The Unicode Standard, Version 4.0, de

39、fined by: The Unicode Standard, Version 4.0 (Boston, MA, Addison-Wesley, 2003. ISBN 0-321-18578-1). 5 4 5BDefinitions 4. Definitions For the purposes of this International Standard, the following definitions apply. Other terms are defined where they appear in italic type or on the left side of a syn

40、tax rule. Terms explicitly defined in this International Standard are not to be presumed to refer implicitly to similar terms defined elsewhere. Terms not defined in this International Standard are to be interpreted according to ISO/IEC 2382.1. Mathematical symbols not defined in this International

41、Standard are to be interpreted according to ISO 31.11. Application refers to an assembly that has an entry point (10.1). When an application is run, a new application domain is created. Several different instantiations of an application can exist on the same machine at the same time, and each has it

42、s own application domain. Application domain an entity that enables application isolation by acting as a container for application state. An application domain acts as a container and boundary for the types defined in the application and the class libraries it uses. Types loaded into one application

43、 domain are distinct from the same type loaded into another application domain, and instances of objects are not directly shared between application domains. For instance, each application domain has its own copy of static variables for these types, and a static constructor for a type is run at most

44、 once per application domain. Implementations are free to provide implementation-specific policy or mechanisms for the creation and destruction of application domains. Argument an expression in the comma-separated list bounded by the parentheses in a method or instance constructor call expression or

45、 bounded by the square brackets in an element access expression. It is also known as an actual argument. Assembly refers to one or more files that are output by the compiler as a result of program compilation. An assembly is a configured set of loadable code modules and other resources that together

46、 implement a unit of functionality. An assembly can contain types, the executable code used to implement these types, and references to other assemblies. The physical representation of an assembly is not defined by this specification. Essentially, an assembly is the output of the compiler. Behavior

47、external appearance or action. Behavior, implementation-defined unspecified behavior where each implementation documents how the choice is made. Behavior, undefined behavior, upon use of a non-portable or erroneous construct or of erroneous data, for which this International Standard imposes no requ

48、irements. Possible handling of undefined behavior ranges from ignoring the situation completely with unpredictable results, to behaving during translation or execution in a documented manner characteristic of the environment (with or without the issuance of a diagnostic message), to terminating a tr

49、anslation or execution (with the issuance of a diagnostic message). Behavior, unspecified behavior where this International Standard provides two or more possibilities and imposes no further requirements on which is chosen in any instance. Class library refers to an assembly that can be used by other assemblies. Use of a class library does not cause the creation of a new application domain. Instead, a class library is loaded into the application domain that uses it. For instance, when an application uses a class library, th

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 标准规范 > 国际标准 > 其他

copyright@ 2008-2019 麦多课文库(www.mydoc123.com)网站版权所有
备案/许可证编号:苏ICP备17064731号-1