c#语言参考手册-英文版.doc_第1页
c#语言参考手册-英文版.doc_第2页
c#语言参考手册-英文版.doc_第3页
c#语言参考手册-英文版.doc_第4页
c#语言参考手册-英文版.doc_第5页
已阅读5页,还剩272页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

C# Language ReferenceOwners:Anders Hejlsberg and Scott WiltamuthFile:C# Language Reference.docLast saved:6/27/2000Last printed:6/9/2000Version0.17bNoticeThis documentation is an early release of the final documentation, which may be changed substantially prior to final commercial release, and is information of Microsoft Corporation.This document is provided for informational purposes only and Microsoft makes no warranties, either express or implied, in this document. Information in this document is subject to change without notice. The entire risk of the use or the results of the use of this document remains with the user. Complying with all applicable copyright laws is the responsibility of the user. Without limiting the rights under copyright, no part of this document may be reproduced, stored in or introduced into a retrieval system, or transmitted in any form or by any means (electronic, mechanical, photocopying, recording, or otherwise), or for any purpose, without the express written permission of Microsoft Corporation.Microsoft may have patents, patent applications, trademarks, copyrights, or other intellectual property rights covering subject matter in this document. Except as expressly provided in any written license agreement from Microsoft, the furnishing of this document does not give you any license to these patents, trademarks, copyrights, or other intellectual property.Unpublished work. 1999-2000 Microsoft Corporation. All rights reserved.Microsoft, Windows, Visual Basic, and Visual C+ are either registered trademarks or trademarks of Microsoft Corporation in the U.S.A. and/or other countries.Other product and company names mentioned herein may be the trademarks of their respective owners.Table of Contents1. Introduction11.1 Hello, world11.2 Automatic memory management21.3 Types41.4 Predefined types51.5 Array types71.6 Type system unification91.7 Statements101.7.1 Statement lists and blocks101.7.2 Labeled statements and goto statements101.7.3 Local declarations of constants and variables111.7.4 Expression statements111.7.5 The if statement111.7.6 The switch statement121.7.7 The while statement121.7.8 The do statement131.7.9 The for statement131.7.10 The foreach statement131.7.11 The break statement and the continue statement141.7.12 The return statement141.7.13 The throw statement141.7.14 The try statement141.7.15 The checked and unchecked statements141.7.16 The lock statement141.8 Classes141.9 Structs151.10 Interfaces151.11 Delegates171.12 Enums181.13 Namespaces181.14 Properties191.15 Indexers201.16 Events211.17 Versioning221.18 Attributes242. Lexical structure272.1 Phases of translation272.2 Grammar notation272.3 Pre-processing282.3.1 Pre-processing declarations282.3.2 #if, #elif, #else, #endif292.3.3 Pre-processing control lines302.3.4 #line312.3.5 Pre-processing identifiers312.3.6 Pre-processing expressions312.3.7 Interaction with white space322.4 Lexical analysis332.4.1 Input332.4.2 Input characters332.4.3 Line terminators332.4.4 Comments332.4.5 White space332.4.6 Tokens332.5 Processing of Unicode character escape sequences342.5.1 Identifiers342.5.2 Keywords362.5.3 Literals3 Boolean literals3 Integer literals3 Real literals3 Character literals3 String literals3 The null literal402.5.4 Operators and punctuators403. Basic concepts413.1 Declarations413.2 Members433.2.1 Namespace members433.2.2 Struct members433.2.3 Enumeration members443.2.4 Class members443.2.5 Interface members443.2.6 Array members443.2.7 Delegate members443.3 Member access443.3.1 Declared accessibility443.3.2 Accessibility domains453.3.3 Protected access473.3.4 Accessibility constraints483.4 Signatures and overloading493.5 Scopes503.5.1 Name hiding5 Hiding through nesting5 Hiding through inheritance533.6 Namespace and type names543.6.1 Fully qualified names554. Types574.1 Value types574.1.1 Default constructors584.1.2 Struct types594.1.3 Simple types594.1.4 Integral types604.1.5 Floating point types614.1.6 The decimal type624.1.7 The bool type634.1.8 Enumeration types634.2 Reference types634.2.1 Class types644.2.2 The object type644.2.3 The string type644.2.4 Interface types644.2.5 Array types644.2.6 Delegate types644.3 Boxing and unboxing654.3.1 Boxing conversions654.3.2 Unboxing conversions665. Variables675.1 Variable categories675.1.1 Static variables675.1.2 Instance variables6 Instance variables in classes6 Instance variables in structs685.1.3 Array elements685.1.4 Value parameters685.1.5 Reference parameters685.1.6 Output parameters685.1.7 Local variables695.2 Default values695.3 Definite assignment695.3.1 Initially assigned variables725.3.2 Initially unassigned variables725.4 Variable references726. Conversions736.1 Implicit conversions736.1.1 Identity conversion736.1.2 Implicit numeric conversions736.1.3 Implicit enumeration conversions746.1.4 Implicit reference conversions746.1.5 Boxing conversions746.1.6 Implicit constant expression conversions746.1.7 User-defined implicit conversions756.2 Explicit conversions756.2.1 Explicit numeric conversions756.2.2 Explicit enumeration conversions766.2.3 Explicit reference conversions766.2.4 Unboxing conversions776.2.5 User-defined explicit conversions776.3 Standard conversions776.3.1 Standard implicit conversions776.3.2 Standard explicit conversions786.4 User-defined conversions786.4.1 Permitted user-defined conversions786.4.2 Evaluation of user-defined conversions786.4.3 User-defined implicit conversions796.4.4 User-defined explicit conversions807. Expressions817.1 Expression classifications817.1.1 Values of expressions827.2 Operators827.2.1 Operator precedence and associativity827.2.2 Operator overloading837.2.3 Unary operator overload resolution847.2.4 Binary operator overload resolution857.2.5 Candidate user-defined operators857.2.6 Numeric promotions8 Unary numeric promotions8 Binary numeric promotions867.3 Member lookup867.3.1 Base types877.4 Function members877.4.1 Argument lists897.4.2 Overload resolution9 Applicable function member9 Better function member9 Better conversion927.4.3 Function member invocation9 Invocations on boxed instances937.4.4 Virtual function member lookup947.4.5 Interface function member lookup947.5 Primary expressions947.5.1 Literals947.5.2 Simple names9 Invariant meaning in blocks957.5.3 Parenthesized expressions967.5.4 Member access9 Identical simple names and type names987.5.5 Invocation expressions9 Method invocations9 Delegate invocations997.5.6 Element access100 Array access100 Indexer access100 String indexing1017.5.7 This access1017.5.8 Base access1027.5.9 Postfix increment and decrement operators1027.5.10 new operator10 Object creation expressions10 Array creation expressions10 Delegate creation expressions1067.5.11 typeof operator1077.5.12 sizeof operator1087.5.13 checked and unchecked operators1087.6 Unary expressions1107.6.1 Unary plus operator1107.6.2 Unary minus operator1117.6.3 Logical negation operator1117.6.4 Bitwise complement operator1117.6.5 Indirection operator1127.6.6 Address operator1127.6.7 Prefix increment and decrement operators1127.6.8 Cast expressions1137.7 Arithmetic operators1137.7.1 Multiplication operator1137.7.2 Division operator1147.7.3 Remainder operator1157.7.4 Addition operator1167.7.5 Subtraction operator1177.8 Shift operators1187.9 Relational operators1197.9.1 Integer comparison operators1207.9.2 Floating-point comparison operators1217.9.3 Decimal comparison operators1217.9.4 Boolean equality operators1227.9.5 Enumeration comparison operators1227.9.6 Reference type equality operators1227.9.7 String equality operators1237.9.8 Delegate equality operators1247.9.9 The is operator1247.10 Logical operators1247.10.1 Integer logical operators1247.10.2 Enumeration logical operators1257.10.3 Boolean logical operators1257.11 Conditional logical operators1257.11.1 Boolean conditional logical operators1267.11.2 User-defined conditional logical operators1267.12 Conditional operator1277.13 Assignment operators1277.13.1 Simple assignment1287.13.2 Compound assignment1307.13.3 Event assignment1307.14 Expression1307.15 Constant expressions1317.16 Boolean expressions1328. Statements1338.1 End points and reachability1338.2 Blocks1358.2.1 Statement lists1358.3 The empty statement1358.4 Labeled statements1368.5 Declaration statements1368.5.1 Local variable declarations1368.5.2 Local constant declarations1378.6 Expression statements1388.7 Selection statements1388.7.1 The if statement1388.7.2 The switch statement1398.8 Iteration statements1428.8.1 The while statement1438.8.2 The do statement1438.8.3 The for statement1448.8.4 The foreach statement1458.9 Jump statements1468.9.1 The break statement1468.9.2 The continue statement1478.9.3 The goto statement1478.9.4 The return statement1488.9.5 The throw statement1498.10 The try statement1508.11 The checked and unchecked statements1528.12 The lock statement1529. Namespaces1559.1 Compilation units1559.2 Namespace declarations1559.3 Using directives1569.3.1 Using alias directives1579.3.2 Using namespace directives1599.4 Namespace members1619.5 Type declarations16110. Classes16310.1 Class declarations16310.1.1 Class modifiers163 Abstract classes163 Sealed classes16410.1.2 Class base specification164 Base classes164 Interface implementations16510.1.3 Class body16610.2 Class members16610.2.1 Inheritance16710.2.2 The new modifier16710.2.3 Access modifiers16810.2.4 Constituent types16810.2.5 Static and instance members16810.2.6 Nested types16910.3 Constants16910.4 Fields17010.4.1 Static and instance fields17110.4.2 Readonly fields17 Using static readonly fields for constants17 Versioning of constants and static readonly fields17210.4.3 Field initialization17310.4.4 Variable initializers173 Static field initialization174 Instance field initialization17410.5 Methods17510.5.1 Method parameters176 Value parameters177 Reference parameters177 Output parameters178 Params parameters17810.5.2 Static and instance methods18010.5.3 Virtual methods18010.5.4 Override methods18210.5.5 Abstract methods18310.5.6 External methods18410.5.7 Method body18510.5.8 Method overloading18510.6 Properties18510.6.1 Static properties18610.6.2 Accessors18710.6.3 Virtual, override, and abstract accessors19110.7 Events19310.8 Indexers19610.8.1 Indexer overloading19910.9 Operators19910.9.1 Unary operators20010.9.2 Binary operators20010.9.3 Conversion operators20110.10 Instance constructors20210.10.1 Constructor initializers20310.10.2 Instance variable initializers20310.10.3 Constructor execution20310.10.4 Default constructors20510.10.5 Private constructors20610.10.6 Optional constructor parameters20610.11 Destructors20610.12 Static constructors20710.12.1 Class loading and initialization20811. Structs21111.1 Struct declarations21111.1.1 Struct modifiers21111.1.2 Interfaces21111.1.3 Struct body21111.2 Struct members21111.3 Struct examples21111.3.1 Database integer type21111.3.2 Database boolean type21312. Arrays21512.1 Array types21512.1.1 The System.Array type21612.2 Array creation21612.3 Array element access21612.4 Array members21612.5 Array covariance21612.6 Array initializers21713. Interfaces21913.1 Interface declarations21913.1.1 Interface modifiers21913.1.2 Base interfaces21913.1.3 Interface body22013.2 Interface members22013.2.1 Interface methods22113.2.2 Interface properties22113.2.3 Interface events22213.2.4 Interface indexers22213.2.5 Interface member access22213.3 Fully qualified interface member names22413.4 Interface implementations22413.4.1 Explicit interface member implementations22513.4.2 Interface mapping22713.4.3 Interface implementation inheritance22913.4.4 Interface re-implementation23113.4.5 Abstract classes and interfaces23214. Enums23314.1 Enum declarations23314.2 Enum members23414.3 Enum values and operations23615. Delegates23715.1 Delegate declarations23715.1.1 Delegate modifiers23716. Exceptions23917. Attributes24117.1 Attribute classes24117.1.1 The AttributeUsage attribute24117.1.2 Positional and named parameters24217.1.3 Attribute parameter types24217.2 Attribute specification24317.3 Attribute instances24517.3.1 Compilation of an attribute24517.3.2 Run-time retrieval of an attribute instance24517.4 Reserved attributes24517.4.1 The AttributeUsage attribute24617.4.2 The Conditional attribute24617.4.3 The Obsolete attribute24818. Versioning25119. Unsafe code25319.1 Unsafe code25319.2 Pointer types25320. Interoperability25520.1 Attributes25520.1.1 The COMImport attribute25520.1.2 The COMSourceInterfaces attribute25520.1.3 The COMVisibility attribute25520.1.4 The DispId attribute25620.1.5 The DllImport attribute25620.1.6 The GlobalObject attribute25720.1.7 The Guid attribute25720.1.8 The HasDefaultInterface attribute25720.1.9 The ImportedFromCOM attribute25720.1.10 The In and Out attributes25720.1.11 The InterfaceType attribute25820.1.12 The IsCOMRegisterFunction attribute25820.1.13 The Marshal attribute25820.1.14 The Name attribute25920.1.15 The NoIDispatch attribute25920.1.16 The NonSerialized attribute25920.1.17 The Predeclared attribute26020.1.18 The ReturnsHResult attribute26020.1.19 The Serializable attribute26020.1.20 The StructLayout attribute26020.1.21 The StructOffset attribute26120.1.22 The TypeLibFunc attribute26120.1.23 The TypeLibType attribute26120.1.24 The TypeLibVar attribute26220.2 Supporting enums26221. References2651. IntroductionC# is a simple, modern, object oriented, and type-safe programming language derived from C and C+. C# (pronounced “C sharp”) is firmly planted in the C and C+ family tree of languages, and will immediately be familiar to C and C+ programmers. C# aims to combine the high productivity of Visual Basic and the raw power of C+.C# is provided as a part of Microsoft Visual Studio 7.0. In addition to C#, Visual Studio supports Visual Basic, Visual C+, and the scripting languages VBScript and JScript. All of these languages provide access to the Next Generation Windows Services (NWGS) platform, which includes a common execution engine and a rich class library. The .NET software development kit defines a Common Language Subset (CLS), a sort of lingua franca that ensures seamless interoperability between CLS-compliant languages and class libraries. For C# developers, this means that even though C# is a new language, it has complete access to the same rich class libraries that are used by seasoned tools such as Visual Basic and Visual C+. C# itself does not include a class library.The rest of this chapter describes the essential features of the language. While later chapters describe rules and exceptions in a detail-oriented and sometimes mathematical manner, this chapter strives for clarity and brevity at the expense of completeness. The intent is to provide the reader with an introduction to the language that will facilitate the writing of early programs and the reading of later chapters.1.1 Hello, worldThe canonical “Hello, world” program can be written in C# as follows:using System;class Hellostatic void Main() Console.WriteLine(Hello, world);The default file extension for C# programs is .cs, as in hello.cs. Such a program can be compiled with the command line directivecsc hello.cswhich produces an executable program named hello.exe. The output of the program is:Hello, worldClose examination of this program is illuminating: The using System; directive references a namespace called System that is provided by the .NET runtime. This namespace contains the Console class referred to in the Main method. Namespaces provide a hierarchical means of organizing the elements of a class library. A “using” directive enables unqualified use of the members of a namespace. The “Hello, world” program uses Console.WriteLine as a shorthand for System.Console.WriteLine. What do these identifiers denote? System is a namespace, Console is a class defined in that namespace, and WriteLine is a static method defined on that class. The Main function is a static member of the class Hello. Functions and variables are not supported at the global level; such elements are always contained within type declarations (e.g., class and struct declarations). The “Hello, world” output is produced through the use of a class library. C# does not itself provide a class library. Instead, C# uses a common class library that is also used by other languages such

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论