《CSharp Language Specification 4.doc》由会员分享,可在线阅读,更多相关《CSharp Language Specification 4.doc(521页珍藏版)》请在金锄头文库上搜索。
1、C#Language SpecificationVersion 4.0Notice 1999-2010 Microsoft Corporation. All rights reserved.Microsoft, Windows, Visual Basic, Visual C#, and Visual C+ are either registered trademarks or trademarks of Microsoft Corporation in the U.S.A. and/or other countries/regions.Other product and company nam
2、es mentioned herein may be the trademarks of their respective owners.Copyright Microsoft Corporation 1999-2010. All Rights Reserved.Please send corrections, comments, and other feedback to Table of ContentsTable of Contents1. Introduction11.1 Hello world11.2 Program structure21.3 Types and variables
3、41.4 Expressions61.5 Statements81.6 Classes and objects121.6.1 Members121.6.2 Accessibility131.6.3 Type parameters131.6.4 Base classes141.6.5 Fields141.6.6 Methods151.6.6.1 Parameters151.6.6.2 Method body and local variables161.6.6.3 Static and instance methods171.6.6.4 Virtual, override, and abstra
4、ct methods181.6.6.5 Method overloading201.6.7 Other function members211.6.7.1 Constructors221.6.7.2 Properties231.6.7.3 Indexers231.6.7.4 Events241.6.7.5 Operators241.6.7.6 Destructors251.7 Structs251.8 Arrays261.9 Interfaces271.10 Enums291.11 Delegates301.12 Attributes312. Lexical structure332.1 Pr
5、ograms332.2 Grammars332.2.1 Grammar notation332.2.2 Lexical grammar342.2.3 Syntactic grammar342.3 Lexical analysis342.3.1 Line terminators352.3.2 Comments352.3.3 White space372.4 Tokens372.4.1 Unicode character escape sequences372.4.2 Identifiers382.4.3 Keywords392.4.4 Literals402.4.4.1 Boolean lite
6、rals402.4.4.2 Integer literals402.4.4.3 Real literals412.4.4.4 Character literals422.4.4.5 String literals432.4.4.6 The null literal452.4.5 Operators and punctuators452.5 Pre-processing directives452.5.1 Conditional compilation symbols472.5.2 Pre-processing expressions472.5.3 Declaration directives4
7、82.5.4 Conditional compilation directives492.5.5 Diagnostic directives512.5.6 Region directives522.5.7 Line directives522.5.8 Pragma directives532.5.8.1 Pragma warning533. Basic concepts553.1 Application Startup553.2 Application termination563.3 Declarations563.4 Members583.4.1 Namespace members583.
8、4.2 Struct members593.4.3 Enumeration members593.4.4 Class members593.4.5 Interface members603.4.6 Array members603.4.7 Delegate members603.5 Member access603.5.1 Declared accessibility603.5.2 Accessibility domains613.5.3 Protected access for instance members633.5.4 Accessibility constraints643.6 Si
9、gnatures and overloading653.7 Scopes663.7.1 Name hiding693.7.1.1 Hiding through nesting693.7.1.2 Hiding through inheritance703.8 Namespace and type names713.8.1 Fully qualified names733.9 Automatic memory management733.10 Execution order764. Types774.1 Value types774.1.1 The System.ValueType type784
10、.1.2 Default constructors784.1.3 Struct types794.1.4 Simple types794.1.5 Integral types804.1.6 Floating point types814.1.7 The decimal type824.1.8 The bool type834.1.9 Enumeration types834.1.10 Nullable types834.2 Reference types834.2.1 Class types844.2.2 The object type854.2.3 The dynamic type854.2
11、.4 The string type854.2.5 Interface types854.2.6 Array types854.2.7 Delegate types854.3 Boxing and unboxing864.3.1 Boxing conversions864.3.2 Unboxing conversions874.4 Constructed types884.4.1 Type arguments894.4.2 Open and closed types894.4.3 Bound and unbound types894.4.4 Satisfying constraints894.
12、5 Type parameters904.6 Expression tree types914.7 The dynamic type925. Variables935.1 Variable categories935.1.1 Static variables935.1.2 Instance variables935.1.2.1 Instance variables in classes935.1.2.2 Instance variables in structs945.1.3 Array elements945.1.4 Value parameters945.1.5 Reference par
13、ameters945.1.6 Output parameters945.1.7 Local variables955.2 Default values965.3 Definite assignment965.3.1 Initially assigned variables975.3.2 Initially unassigned variables975.3.3 Precise rules for determining definite assignment975.3.3.1 General rules for statements985.3.3.2 Block statements, che
14、cked, and unchecked statements985.3.3.3 Expression statements985.3.3.4 Declaration statements985.3.3.5 If statements985.3.3.6 Switch statements995.3.3.7 While statements995.3.3.8 Do statements995.3.3.9 For statements1005.3.3.10 Break, continue, and goto statements1005.3.3.11 Throw statements1005.3.3.12 Return statements1005.3.3.13 Try-catch statements1005.3.3.14 Try-finally statements1015.3.3.15 Try-catch-finally statements1015.3.3.16 Foreach statements1025.3.3.17 Using statements1025.3.3.18 Lock statements1025.3.3.19 Yield statements1035.3.3.20 General rules for sim