c语言参考手册英文版

上传人:痛*** 文档编号:111298335 上传时间:2022-06-20 格式:DOC 页数:273 大小:1.72MB
收藏 版权申诉 举报 下载
c语言参考手册英文版_第1页
第1页 / 共273页
c语言参考手册英文版_第2页
第2页 / 共273页
c语言参考手册英文版_第3页
第3页 / 共273页
资源描述:

《c语言参考手册英文版》由会员分享,可在线阅读,更多相关《c语言参考手册英文版(273页珍藏版)》请在装配图网上搜索。

1、C# Language ReferenceOwners:Anders Hejlsberg and Scott WiltamuthFile:C# Language Reference.docLast saved:2000/6/27 0:23:00Last printed:2022/6/5 8:36:58Version0.17bNoticeThis documentation is an early release of the final documentation, which may be changed substantially prior to final mercial releas

2、e, 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

3、use of this document remains with the user. plying 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 mean

4、s , 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 agreeme

5、nt 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 trade

6、marks or trademarks of Microsoft Corporation in the U.S.A. and/or other countries.Other product and pany 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

7、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

8、 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 Str

9、ucts151.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, #e

10、ndif292.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 ments332.4.5 White space332.4.6 Tokens332.5 Processi

11、ng of Unicode character escape sequences342.5.1 Identifiers342.5.2 Keywords362.5.3 Literals362.5.3.1 Boolean literals362.5.3.2 Integer literals362.5.3.3 Real literals372.5.3.4 Character literals382.5.3.5 String literals392.5.3.6 The null literal402.5.4 Operators and punctuators403. Basic concepts413

12、.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

13、.4 Accessibility constraints483.4 Signatures and overloading493.5 Scopes503.5.1 Name hiding523.5.1.1 Hiding through nesting523.5.1.2 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

14、 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

15、unboxing654.3.1 Boxing conversions654.3.2 Unboxing conversions665. Variables675.1 Variable categories675.1.1 Static variables675.1.2 Instance variables675.1.2.1 Instance variables in classes675.1.2.2 Instance variables in structs685.1.3 Array elements685.1.4 Value parameters685.1.5 Reference paramet

16、ers685.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 conversions

17、736.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

18、.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

19、-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 r

20、esolution847.2.4 Binary operator overload resolution857.2.5 Candidate user-defined operators857.2.6 Numeric promotions857.2.6.1 Unary numeric promotions867.2.6.2 Binary numeric promotions867.3 Member lookup867.3.1 Base types877.4 Function members877.4.1 Argument lists897.4.2 Overload resolution917.4

21、.2.1 Applicable function member917.4.2.2 Better function member927.4.2.3 Better conversion927.4.3 Function member invocation927.4.3.1 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 na

22、mes947.5.2.1 Invariant meaning in blocks957.5.3 Parenthesized expressions967.5.4 Member access967.5.4.1 Identical simple names and type names987.5.5 Invocation expressions987.5.5.1 Method invocations997.5.5.2 Delegate invocations997.5.6 Element access1007.5.6.1 Array access1007.5.6.2 Indexer access1

23、007.5.6.3 String indexing1017.5.7 This access1017.5.8 Base access1027.5.9 Postfix increment and decrement operators1027.5.10 new operator1037.5.10.1 Object creation expressions1037.5.10.2 Array creation expressions1047.5.10.3 Delegate creation expressions1067.5.11 typeof operator1077.5.12 sizeof ope

24、rator1087.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 plement operator1117.6.5 Indirection operator1127.6.6 Address operator1127.6.7 Prefix increment and decrement operators112

25、7.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 parison operators1207.9.2 Floating-point pari

26、son operators1217.9.3 Decimal parison operators1217.9.4 Boolean equality operators1227.9.5 Enumeration parison 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 l

27、ogical 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 a

28、ssignment1287.13.2 pound 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 statement

29、s1368.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

30、 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

31、 pilation 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 modifiers16310.1.1.1 Abstract classes16310.1.1.2 Sealed classes

32、16410.1.2 Class base specification16410.1.2.1 Base classes16410.1.2.2 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

33、.3 Constants16910.4 Fields17010.4.1 Static and instance fields17110.4.2 Readonly fields17210.4.2.1 Using static readonly fields for constants17210.4.2.2 Versioning of constants and static readonly fields17210.4.3 Field initialization17310.4.4 Variable initializers17310.4.4.1 Static field initializat

34、ion17410.4.4.2 Instance field initialization17410.5 Methods17510.5.1 Method parameters17610.5.1.1 Value parameters17710.5.1.2 Reference parameters17710.5.1.3 Output parameters17810.5.1.4 Params parameters17810.5.2 Static and instance methods18010.5.3 Virtual methods18010.5.4 Override methods18210.5.

35、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

36、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 par

37、ameters20610.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

38、 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 interfaces21

39、913.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 m

40、ember 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 decl

41、arations23715.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 pilation of an attribut

42、e24517.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 Attribut

43、es25520.1.1 The Import attribute25520.1.2 The SourceInterfaces attribute25520.1.3 The Visibility 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 ImportedFr

44、om attribute25720.1.10 The In and Out attributes25720.1.11 The InterfaceType attribute25820.1.12 The IsRegisterFunction 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 attribute

45、26020.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. References26

46、5.1. IntroductionC# is a simple, modern, object oriented, and type-safe programming language derived from C and C+. C# 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 bine the high productivity of Visual Basic and the r

47、aw 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 platform, which includes a mon ex

48、ecution engine and a rich class library. The .NET software development kit defines a mon Language Subset , a sort of lingua franca that ensures seamless interoperability between CLS-pliant languages and class libraries. For C# developers, this means that even though C# is a new language, it has plet

49、e 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

50、and sometimes mathematical manner, this chapter strives for clarity and brevity at the expense of pleteness. 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 Hel

51、lo, world program can be written in C# as follows:using System;class Hellostatic void Main Console.WriteLine;The default file extension for C# programs is .cs, as in hello.cs. Such a program can be piled with the mand line directivecsc hello.cswhich produces an executable program named hello.exe. Th

52、e 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

53、 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 . What do these identifiers denote? System is a namespace, Console is a class defined in that namespace, a

54、nd 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 . The Hello, world output is produced through the use of a class

55、library. C# does not itself provide a class library. Instead, C# uses a mon class library that is also used by other languages such as Visual Basic and Visual C+.For C and C+ developers, it is interesting to note a few things that do not appear in the Hello, world program. The program does not use e

56、ither : or - operators. The : is not an operator in C# at all, and the - operator is used in only a small fraction of C# programs. C# programs use . as a separator in pound names such as Console.WriteLine. The program does not contain forward declarations. Forward declarations are never needed in C#

57、 programs, as declaration order is not significant. The program does not use #include to import program text. Dependencies between programs are handled symbolically rather than with program text. This system eliminates barriers between programs written in different languages. For example, the Consol

58、e class could be written in C# or in some other language.1.2 Automatic memory managementManual memory management requires developers to manage the allocation and de-allocation of blocks of memory. Manual memory management is both time consuming and difficult. C# provides automatic memory management

59、so that developers are freed from this burdensome task. In the vast majority of cases, this automatic memory management increases code quality and enhances developer productivity without negatively impacting either expressiveness or performance.The exampleusing System;public class Stackprivate Node

60、first = null;public bool Empty get return ;public object Pop if throw new Exception;else object temp = first.Value;first = first.Next;return temp;public void Push first = new Node;class Nodepublic Node Next;public object Value;public Node: this public Node Next = next;Value = value;shows a Stack cla

61、ss implemented as a linked list of Node instances. Node instances are created in the Push method and are garbage collected when no longer needed. A Node instance bees eligible for garbage collection when it is no longer possible for any code to access it. For instance, when an item is removed from the Stack, the associated Node instance bees eligible for garbage collection.The exampleclass Teststatic void Main Stack s = new Stack;for int i = 0; i s.Push;while Console.WriteLines.Pop;shows a test program

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

copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!