1. Trang chủ
  2. » Công Nghệ Thông Tin

Tài liệu lập trình C# - Ngôn ngữ kỹ thuật

541 6 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

C # (phát âm là Xem Sharp) là một đơn giản, hiện đại, ngôn ngữ lập trình hướng đối tượng, và kiểu an toàn. C # có nguồn gốc từ gia đình C của ngôn ngữ và sẽ được ngay lập tức quen thuộc với C, C + +, và các lập trình Java. C # được chuẩn hóa ECMA quốc tế như là tiêu chuẩn ECMA-334 và theo tiêu chuẩn ISO / IEC là ISO / IEC 23270 tiêu chuẩn. Microsoft C # trình biên dịch cho. NET Framework là một thực hiện phù hợp của cả hai tiêu chuẩn....

# C Language Specification Version 4.0 Copyright Ó Microsoft Corporation 1999-2010 All Rights Reserved Please send corrections, comments, and other feedback to csharp@microsoft.com Notice © 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 names mentioned herein may be the trademarks of their respective owners Copyright Ó Microsoft Corporation 1999-2010 All Rights Reserved Table of Contents Table of Contents Introduction 1.1 Hello world 1.2 Program structure 1.3 Types and variables 1.4 Expressions 1.5 Statements 1.6 Classes and objects 12 1.6.1 Members 12 1.6.2 Accessibility 13 1.6.3 Type parameters 13 1.6.4 Base classes 14 1.6.5 Fields .14 1.6.6 Methods 15 1.6.6.1 Parameters 15 1.6.6.2 Method body and local variables 16 1.6.6.3 Static and instance methods 17 1.6.6.4 Virtual, override, and abstract methods 18 1.6.6.5 Method overloading 20 1.6.7 Other function members 21 1.6.7.1 Constructors .22 1.6.7.2 Properties 23 1.6.7.3 Indexers 23 1.6.7.4 Events .24 1.6.7.5 Operators 24 1.6.7.6 Destructors .25 1.7 Structs 25 1.8 Arrays 26 1.9 Interfaces 27 1.10 Enums 29 1.11 Delegates 30 1.12 Attributes 31 Lexical structure 33 2.1 Programs 33 2.2 Grammars 33 2.2.1 Grammar notation 33 2.2.2 Lexical grammar .34 2.2.3 Syntactic grammar 34 2.3 Lexical analysis 34 2.3.1 Line terminators 35 2.3.2 Comments .35 2.3.3 White space .37 2.4 Tokens 37 2.4.1 Unicode character escape sequences .37 2.4.2 Identifiers 38 2.4.3 Keywords 39 2.4.4 Literals 40 2.4.4.1 Boolean literals 40 2.4.4.2 Integer literals 40 Copyright Ó Microsoft Corporation 1999-2010 All Rights Reserved iii C# Language Specification 2.4.4.3 Real literals 41 2.4.4.4 Character literals 42 2.4.4.5 String literals 43 2.4.4.6 The null literal 45 2.4.5 Operators and punctuators 45 2.5 Pre-processing directives 45 2.5.1 Conditional compilation symbols 47 2.5.2 Pre-processing expressions 47 2.5.3 Declaration directives .48 2.5.4 Conditional compilation directives 49 2.5.5 Diagnostic directives 51 2.5.6 Region directives 52 2.5.7 Line directives 52 2.5.8 Pragma directives 53 2.5.8.1 Pragma warning .53 Basic concepts 55 3.1 Application Startup 55 3.2 Application termination 56 3.3 Declarations 56 3.4 Members 58 3.4.1 Namespace members 58 3.4.2 Struct members .59 3.4.3 Enumeration members 59 3.4.4 Class members 59 3.4.5 Interface members 60 3.4.6 Array members .60 3.4.7 Delegate members 60 3.5 Member access 60 3.5.1 Declared accessibility .60 3.5.2 Accessibility domains .61 3.5.3 Protected access for instance members 63 3.5.4 Accessibility constraints 64 3.6 Signatures and overloading 65 3.7 Scopes 66 3.7.1 Name hiding 69 3.7.1.1 Hiding through nesting 69 3.7.1.2 Hiding through inheritance 70 3.8 Namespace and type names 71 3.8.1 Fully qualified names .73 3.9 Automatic memory management 73 3.10 Execution order 76 Types 77 4.1 Value types 77 4.1.1 The System.ValueType type 78 4.1.2 Default constructors .78 4.1.3 Struct types .79 4.1.4 Simple types 79 4.1.5 Integral types 80 4.1.6 Floating point types 81 iv Copyright Ó Microsoft Corporation 1999-2010 All Rights Reserved Table of Contents 4.1.7 The decimal type 82 4.1.8 The bool type 83 4.1.9 Enumeration types 83 4.1.10 Nullable types .83 4.2 Reference types 83 4.2.1 Class types 84 4.2.2 The object type .85 4.2.3 The dynamic type 85 4.2.4 The string type 85 4.2.5 Interface types 85 4.2.6 Array types 85 4.2.7 Delegate types 85 4.3 Boxing and unboxing 86 4.3.1 Boxing conversions 86 4.3.2 Unboxing conversions 87 4.4 Constructed types 88 4.4.1 Type arguments .89 4.4.2 Open and closed types 89 4.4.3 Bound and unbound types 89 4.4.4 Satisfying constraints .89 4.5 Type parameters 90 4.6 Expression tree types 91 4.7 The dynamic type 92 Variables 93 5.1 Variable categories 93 5.1.1 Static variables 93 5.1.2 Instance variables 93 5.1.2.1 Instance variables in classes 93 5.1.2.2 Instance variables in structs .94 5.1.3 Array elements 94 5.1.4 Value parameters .94 5.1.5 Reference parameters .94 5.1.6 Output parameters 94 5.1.7 Local variables 95 5.2 Default values 96 5.3 Definite assignment 96 5.3.1 Initially assigned variables .97 5.3.2 Initially unassigned variables 97 5.3.3 Precise rules for determining definite assignment 97 5.3.3.1 General rules for statements 98 5.3.3.2 Block statements, checked, and unchecked statements 98 5.3.3.3 Expression statements .98 5.3.3.4 Declaration statements .98 5.3.3.5 If statements .98 5.3.3.6 Switch statements 99 5.3.3.7 While statements 99 5.3.3.8 Do statements 99 5.3.3.9 For statements 100 5.3.3.10 Break, continue, and goto statements 100 5.3.3.11 Throw statements 100 Copyright Ó Microsoft Corporation 1999-2010 All Rights Reserved v C# Language Specification 5.3.3.12 Return statements 100 5.3.3.13 Try-catch statements 100 5.3.3.14 Try-finally statements 101 5.3.3.15 Try-catch-finally statements 101 5.3.3.16 Foreach statements 102 5.3.3.17 Using statements 102 5.3.3.18 Lock statements 102 5.3.3.19 Yield statements 103 5.3.3.20 General rules for simple expressions 103 5.3.3.21 General rules for expressions with embedded expressions 103 5.3.3.22 Invocation expressions and object creation expressions 103 5.3.3.23 Simple assignment expressions 104 5.3.3.24 && expressions 104 5.3.3.25 || expressions 105 5.3.3.26 ! expressions 106 5.3.3.27 ?? expressions 106 5.3.3.28 ?: expressions .106 5.3.3.29 Anonymous functions 107 5.4 Variable references 107 5.5 Atomicity of variable references 107 Conversions 109 6.1 Implicit conversions 109 6.1.1 Identity conversion .109 6.1.2 Implicit numeric conversions .110 6.1.3 Implicit enumeration conversions 110 6.1.4 Implicit nullable conversions .110 6.1.5 Null literal conversions 111 6.1.6 Implicit reference conversions .111 6.1.7 Boxing conversions 111 6.1.8 Implicit dynamic conversions 112 6.1.9 Implicit constant expression conversions 112 6.1.10 Implicit conversions involving type parameters 112 6.1.11 User-defined implicit conversions .113 6.1.12 Anonymous function conversions and method group conversions 113 6.2 Explicit conversions 113 6.2.1 Explicit numeric conversions .114 6.2.2 Explicit enumeration conversions 115 6.2.3 Explicit nullable conversions .115 6.2.4 Explicit reference conversions .116 6.2.5 Unboxing conversions 117 6.2.6 Explicit dynamic conversions 117 6.2.7 Explicit conversions involving type parameters 118 6.2.8 User-defined explicit conversions 119 6.3 Standard conversions 119 6.3.1 Standard implicit conversions 119 6.3.2 Standard explicit conversions .119 6.4 User-defined conversions 119 6.4.1 Permitted user-defined conversions .119 6.4.2 Lifted conversion operators 120 6.4.3 Evaluation of user-defined conversions .120 vi Copyright Ó Microsoft Corporation 1999-2010 All Rights Reserved Table of Contents 6.4.4 User-defined implicit conversions .121 6.4.5 User-defined explicit conversions 122 6.5 Anonymous function conversions 123 6.5.1 Evaluation of anonymous function conversions to delegate types .124 6.5.2 Evaluation of anonymous function conversions to expression tree types 124 6.5.3 Implementation example 124 6.6 Method group conversions 127 Expressions 131 7.1 Expression classifications 131 7.1.1 Values of expressions 132 7.2 Static and Dynamic Binding 132 7.2.1 Binding-time 133 7.2.2 Dynamic binding 133 7.2.3 Types of constituent expressions 133 7.3 Operators 134 7.3.1 Operator precedence and associativity 134 7.3.2 Operator overloading 135 7.3.3 Unary operator overload resolution .136 7.3.4 Binary operator overload resolution 137 7.3.5 Candidate user-defined operators 137 7.3.6 Numeric promotions .137 7.3.6.1 Unary numeric promotions 138 7.3.6.2 Binary numeric promotions 138 7.3.7 Lifted operators 139 7.4 Member lookup 139 7.4.1 Base types .141 7.5 Function members 141 7.5.1 Argument lists .143 7.5.1.1 Corresponding parameters .144 7.5.1.2 Run-time evaluation of argument lists 145 7.5.2 Type inference 147 7.5.2.1 The first phase 147 7.5.2.2 The second phase 148 7.5.2.3 Input types 148 7.5.2.4 Output types 148 7.5.2.5 Dependence 148 7.5.2.6 Output type inferences 148 7.5.2.7 Explicit parameter type inferences 148 7.5.2.8 Exact inferences .149 7.5.2.9 Lower-bound inferences 149 7.5.2.10 Upper-bound inferences 150 7.5.2.11 Fixing 150 7.5.2.12 Inferred return type 150 7.5.2.13 Type inference for conversion of method groups .151 7.5.2.14 Finding the best common type of a set of expressions .152 7.5.3 Overload resolution 152 7.5.3.1 Applicable function member 153 7.5.3.2 Better function member 153 7.5.3.3 Better conversion from expression 154 7.5.3.4 Better conversion from type 155 Copyright Ó Microsoft Corporation 1999-2010 All Rights Reserved vii C# Language Specification 7.5.3.5 Better conversion target 155 7.5.3.6 Overloading in generic classes 155 7.5.4 Compile-time checking of dynamic overload resolution 155 7.5.5 Function member invocation 156 7.5.5.1 Invocations on boxed instances .157 7.6 Primary expressions 157 7.6.1 Literals 158 7.6.2 Simple names 158 7.6.2.1 Invariant meaning in blocks 159 7.6.3 Parenthesized expressions 160 7.6.4 Member access .161 7.6.4.1 Identical simple names and type names 162 7.6.4.2 Grammar ambiguities 163 7.6.5 Invocation expressions 164 7.6.5.1 Method invocations .164 7.6.5.2 Extension method invocations 165 7.6.5.3 Delegate invocations 168 7.6.6 Element access 168 7.6.6.1 Array access 168 7.6.6.2 Indexer access 169 7.6.7 This access 170 7.6.8 Base access 170 7.6.9 Postfix increment and decrement operators 171 7.6.10 The new operator 172 7.6.10.1 Object creation expressions 172 7.6.10.2 Object initializers 173 7.6.10.3 Collection initializers 175 7.6.10.4 Array creation expressions 176 7.6.10.5 Delegate creation expressions .178 7.6.10.6 Anonymous object creation expressions .180 7.6.11 The typeof operator 181 7.6.12 The checked and unchecked operators 183 7.6.13 Default value expressions 185 7.6.14 Anonymous method expressions 185 7.7 Unary operators 186 7.7.1 Unary plus operator 186 7.7.2 Unary minus operator 186 7.7.3 Logical negation operator .187 7.7.4 Bitwise complement operator 187 7.7.5 Prefix increment and decrement operators 187 7.7.6 Cast expressions 188 7.8 Arithmetic operators 189 7.8.1 Multiplication operator 189 7.8.2 Division operator 190 7.8.3 Remainder operator 191 7.8.4 Addition operator 192 7.8.5 Subtraction operator .194 7.9 Shift operators 195 7.10 Relational and type-testing operators 197 7.10.1 Integer comparison operators .197 7.10.2 Floating-point comparison operators 198 viii Copyright Ó Microsoft Corporation 1999-2010 All Rights Reserved Table of Contents 7.10.3 Decimal comparison operators 199 7.10.4 Boolean equality operators 199 7.10.5 Enumeration comparison operators 199 7.10.6 Reference type equality operators 199 7.10.7 String equality operators 201 7.10.8 Delegate equality operators 201 7.10.9 Equality operators and null 202 7.10.10 The is operator 202 7.10.11 The as operator 202 7.11 Logical operators 203 7.11.1 Integer logical operators .204 7.11.2 Enumeration logical operators 204 7.11.3 Boolean logical operators 204 7.11.4 Nullable boolean logical operators 204 7.12 Conditional logical operators 205 7.12.1 Boolean conditional logical operators .206 7.12.2 User-defined conditional logical operators 206 7.13 The null coalescing operator 206 7.14 Conditional operator 207 7.15 Anonymous function expressions 208 7.15.1 Anonymous function signatures 210 7.15.2 Anonymous function bodies .210 7.15.3 Overload resolution 211 7.15.4 Anonymous functions and dynamic binding .211 7.15.5 Outer variables 211 7.15.5.1 Captured outer variables 212 7.15.5.2 Instantiation of local variables 212 7.15.6 Evaluation of anonymous function expressions 214 7.16 Query expressions 215 7.16.1 Ambiguities in query expressions 216 7.16.2 Query expression translation 216 7.16.2.1 Select and groupby clauses with continuations 217 7.16.2.2 Explicit range variable types .217 7.16.2.3 Degenerate query expressions .218 7.16.2.4 From, let, where, join and orderby clauses 218 7.16.2.5 Select clauses .221 7.16.2.6 Groupby clauses 222 7.16.2.7 Transparent identifiers 222 7.16.3 The query expression pattern .223 7.17 Assignment operators 224 7.17.1 Simple assignment 225 7.17.2 Compound assignment .227 7.17.3 Event assignment 228 7.18 Expression 228 7.19 Constant expressions228 7.20 Boolean expressions 230 Statements 231 8.1 End points and reachability 231 8.2 Blocks 233 8.2.1 Statement lists .233 Copyright Ó Microsoft Corporation 1999-2010 All Rights Reserved ix C# Language Specification 8.3 The empty statement 234 8.4 Labeled statements 234 8.5 Declaration statements 235 8.5.1 Local variable declarations 235 8.5.2 Local constant declarations 236 8.6 Expression statements 237 8.7 Selection statements 237 8.7.1 The if statement 237 8.7.2 The switch statement 238 8.8 Iteration statements 241 8.8.1 The while statement 242 8.8.2 The statement 242 8.8.3 The for statement 243 8.8.4 The foreach statement 244 8.9 Jump statements 246 8.9.1 The break statement 247 8.9.2 The continue statement 248 8.9.3 The goto statement .248 8.9.4 The return statement .250 8.9.5 The throw statement .250 8.10 The try statement 251 8.11 The checked and unchecked statements 254 8.12 The lock statement 254 8.13 The using statement 255 8.14 The yield statement 257 Namespaces 259 9.1 Compilation units 259 9.2 Namespace declarations 259 9.3 Extern aliases 260 9.4 Using directives 261 9.4.1 Using alias directives 262 9.4.2 Using namespace directives 264 9.5 Namespace members 266 9.6 Type declarations 266 9.7 Namespace alias qualifiers 267 9.7.1 Uniqueness of aliases 268 10 Classes 269 10.1 Class declarations 269 10.1.1 Class modifiers 269 10.1.1.1 Abstract classes 270 10.1.1.2 Sealed classes .270 10.1.1.3 Static classes 270 10.1.2 Partial modifier 271 10.1.3 Type parameters 271 10.1.4 Class base specification 272 10.1.4.1 Base classes 272 10.1.4.2 Interface implementations 274 10.1.5 Type parameter constraints 274 10.1.6 Class body 278 x Copyright Ó Microsoft Corporation 1999-2010 All Rights Reserved Appendix B Grammar type-parameter-list: < type-parameters > type-parameters: attributesopt type-parameter type-parameters , attributesopt type-parameter type-parameter: identifier class-base: : class-type : interface-type-list : class-type , interface-type-list interface-type-list: interface-type interface-type-list , interface-type type-parameter-constraints-clauses: type-parameter-constraints-clause type-parameter-constraints-clauses type-parameter-constraints-clause type-parameter-constraints-clause: where type-parameter : type-parameter-constraints type-parameter-constraints: primary-constraint secondary-constraints constructor-constraint primary-constraint , secondary-constraints primary-constraint , constructor-constraint secondary-constraints , constructor-constraint primary-constraint , secondary-constraints , constructor-constraint primary-constraint: class-type class struct secondary-constraints: interface-type type-parameter secondary-constraints , interface-type secondary-constraints , type-parameter constructor-constraint: new ( ) class-body: { class-member-declarationsopt } class-member-declarations: class-member-declaration class-member-declarations class-member-declaration Copyright Ó Microsoft Corporation 1999-2010 All Rights Reserved 515 C# Language Specification class-member-declaration: constant-declaration field-declaration method-declaration property-declaration event-declaration indexer-declaration operator-declaration constructor-declaration destructor-declaration static-constructor-declaration type-declaration constant-declaration: attributesopt constant-modifiersopt const type constant-declarators ; constant-modifiers: constant-modifier constant-modifiers constant-modifier constant-modifier: new public protected internal private constant-declarators: constant-declarator constant-declarators , constant-declarator constant-declarator: identifier = constant-expression field-declaration: attributesopt field-modifiersopt type variable-declarators ; field-modifiers: field-modifier field-modifiers field-modifier field-modifier: new public protected internal private static readonly volatile variable-declarators: variable-declarator variable-declarators , variable-declarator 516 Copyright Ó Microsoft Corporation 1999-2010 All Rights Reserved Appendix B Grammar variable-declarator: identifier identifier = variable-initializer variable-initializer: expression array-initializer method-declaration: method-header method-body method-header: attributesopt method-modifiersopt partialopt return-type member-name type-parameter-list opt ( formal-parameter-listopt ) type-parameter-constraints-clausesopt method-modifiers: method-modifier method-modifiers method-modifier method-modifier: new public protected internal private static virtual sealed override abstract extern return-type: type void member-name: identifier interface-type identifier method-body: block ; formal-parameter-list: fixed-parameters fixed-parameters , parameter-array parameter-array fixed-parameters: fixed-parameter fixed-parameters , fixed-parameter fixed-parameter: attributesopt parameter-modifieropt type identifier default-argumentopt default-argument: = expression Copyright Ó Microsoft Corporation 1999-2010 All Rights Reserved 517 C# Language Specification parameter-modifier: ref out this parameter-array: attributesopt params array-type identifier property-declaration: attributesopt property-modifiersopt type member-name { accessor-declarations } property-modifiers: property-modifier property-modifiers property-modifier property-modifier: new public protected internal private static virtual sealed override abstract extern member-name: identifier interface-type identifier accessor-declarations: get-accessor-declaration set-accessor-declarationopt set-accessor-declaration get-accessor-declaration opt get-accessor-declaration: attributesopt accessor-modifieropt get accessor-body set-accessor-declaration: attributesopt accessor-modifieropt set accessor-body accessor-modifier: protected internal private protected internal internal protected accessor-body: block ; event-declaration: attributesopt event-modifiersopt event type variable-declarators ; attributesopt event-modifiersopt event type member-name { event-accessor-declarations } 518 Copyright Ó Microsoft Corporation 1999-2010 All Rights Reserved Appendix B Grammar event-modifiers: event-modifier event-modifiers event-modifier event-modifier: new public protected internal private static virtual sealed override abstract extern event-accessor-declarations: add-accessor-declaration remove-accessor-declaration remove-accessor-declaration add-accessor-declaration add-accessor-declaration: attributesopt add block remove-accessor-declaration: attributesopt remove block indexer-declaration: attributesopt indexer-modifiersopt indexer-declarator { accessor-declarations } indexer-modifiers: indexer-modifier indexer-modifiers indexer-modifier indexer-modifier: new public protected internal private virtual sealed override abstract extern indexer-declarator: type this [ formal-parameter-list ] type interface-type this [ formal-parameter-list ] operator-declaration: attributesopt operator-modifiers operator-declarator operator-body operator-modifiers: operator-modifier operator-modifiers operator-modifier Copyright Ó Microsoft Corporation 1999-2010 All Rights Reserved 519 C# Language Specification operator-modifier: public static extern operator-declarator: unary-operator-declarator binary-operator-declarator conversion-operator-declarator unary-operator-declarator: type operator overloadable-unary-operator ( type identifier ) overloadable-unary-operator: one of + - ! ~ ++ true false binary-operator-declarator: type operator overloadable-binary-operator ( type identifier , type identifier ) overloadable-binary-operator: + * / % & | ^ < >= variant-type-parameters: attributesopt variance-annotationopt type-parameter variant-type-parameters , attributesopt variance-annotationopt type-parameter variance-annotation: in out interface-base: : interface-type-list interface-body: { interface-member-declarationsopt } interface-member-declarations: interface-member-declaration interface-member-declarations interface-member-declaration interface-member-declaration: interface-method-declaration interface-property-declaration interface-event-declaration interface-indexer-declaration interface-method-declaration: attributesopt newopt return-type identifier type-parameter-list ( formal-parameter-listopt ) type-parameter-constraints-clausesopt ; interface-property-declaration: attributesopt newopt type identifier { interface-accessors } interface-accessors: attributesopt get attributesopt set attributesopt get attributesopt set ; ; ; attributesopt set ; ; attributesopt get ; interface-event-declaration: attributesopt newopt event type identifier ; interface-indexer-declaration: attributesopt newopt type this [ formal-parameter-list ] { interface-accessors } YY Enums enum-declaration: attributesopt enum-modifiersopt enum identifier enum-baseopt enum-body ;opt Copyright Ó Microsoft Corporation 1999-2010 All Rights Reserved 523 C# Language Specification enum-base: : integral-type enum-body: { enum-member-declarationsopt } { enum-member-declarations , } enum-modifiers: enum-modifier enum-modifiers enum-modifier enum-modifier: new public protected internal private enum-member-declarations: enum-member-declaration enum-member-declarations , enum-member-declaration enum-member-declaration: attributesopt identifier attributesopt identifier = constant-expression ZZ Delegates delegate-declaration: attributesopt delegate-modifiersopt delegate return-type identifier variant-type-parameter-listopt ( formal-parameter-listopt ) type-parameter-constraints-clausesopt ; delegate-modifiers: delegate-modifier delegate-modifiers delegate-modifier delegate-modifier: new public protected internal private AAA Attributes global-attributes: global-attribute-sections global-attribute-sections: global-attribute-section global-attribute-sections global-attribute-section global-attribute-section: [ global-attribute-target-specifier attribute-list ] [ global-attribute-target-specifier attribute-list , ] global-attribute-target-specifier: global-attribute-target : 524 Copyright Ó Microsoft Corporation 1999-2010 All Rights Reserved Appendix B Grammar global-attribute-target: assembly module attributes: attribute-sections attribute-sections: attribute-section attribute-sections attribute-section attribute-section: [ attribute-target-specifieropt attribute-list ] [ attribute-target-specifieropt attribute-list , ] attribute-target-specifier: attribute-target : attribute-target: field event method param property return type attribute-list: attribute attribute-list , attribute attribute: attribute-name attribute-argumentsopt attribute-name: type-name attribute-arguments: ( positional-argument-listopt ) ( positional-argument-list , named-argument-list ) ( named-argument-list ) positional-argument-list: positional-argument positional-argument-list , positional-argument positional-argument: argument-nameopt attribute-argument-expression named-argument-list: named-argument named-argument-list , named-argument named-argument: identifier = attribute-argument-expression attribute-argument-expression: expression Copyright Ó Microsoft Corporation 1999-2010 All Rights Reserved 525 C# Language Specification BBB Grammar extensions for unsafe code class-modifier: unsafe struct-modifier: unsafe interface-modifier: unsafe delegate-modifier: unsafe field-modifier: unsafe method-modifier: unsafe property-modifier: unsafe event-modifier: unsafe indexer-modifier: unsafe operator-modifier: unsafe constructor-modifier: unsafe destructor-declaration: attributesopt externopt unsafeopt ~ identifier ( ) destructor-body attributesopt unsafeopt externopt ~ identifier ( ) destructor-body static-constructor-modifiers: externopt unsafeopt static unsafeopt externopt static externopt static unsafeopt unsafeopt static externopt static externopt unsafeopt static unsafeopt externopt 526 Copyright Ó Microsoft Corporation 1999-2010 All Rights Reserved Appendix B Grammar embedded-statement: unsafe-statement fixed-statement unsafe-statement: unsafe block type: pointer-type pointer-type: unmanaged-type * void * unmanaged-type: type primary-no-array-creation-expression: pointer-member-access pointer-element-access sizeof-expression unary-expression: pointer-indirection-expression addressof-expression pointer-indirection-expression: * unary-expression pointer-member-access: primary-expression -> identifier pointer-element-access: primary-no-array-creation-expression [ expression ] addressof-expression: & unary-expression sizeof-expression: sizeof ( unmanaged-type ) fixed-statement: fixed ( pointer-type fixed-pointer-declarators ) embedded-statement fixed-pointer-declarators: fixed-pointer-declarator fixed-pointer-declarators , fixed-pointer-declarator fixed-pointer-declarator: identifier = fixed-pointer-initializer fixed-pointer-initializer: & variable-reference expression Copyright Ó Microsoft Corporation 1999-2010 All Rights Reserved 527 C# Language Specification struct-member-declaration: … fixed-size-buffer-declaration fixed-size-buffer-declaration: attributesopt fixed-size-buffer-modifiersopt fixed buffer-element-type fixed-size-buffer-declarators ; fixed-size-buffer-modifiers: fixed-size-buffer-modifier fixed-size-buffer-modifier fixed-size-buffer-modifiers fixed-size-buffer-modifier: new public protected internal private unsafe buffer-element-type: type fixed-size-buffer-declarators: fixed-size-buffer-declarator fixed-size-buffer-declarator fixed-size-buffer-declarators fixed-size-buffer-declarator: identifier [ constant-expression ] local-variable-initializer: … stackalloc-initializer stackalloc-initializer: stackalloc unmanaged-type [ expression ] 528 Copyright Ó Microsoft Corporation 1999-2010 All Rights Reserved Appendix B Grammar CCC References Unicode Consortium The Unicode Standard, Version 3.0 Addison-Wesley, Reading, Massachusetts, 2000, ISBN 0-201-616335-5 IEEE IEEE Standard for Binary Floating-Point Arithmetic ANSI/IEEE Standard 754-1985 Available from http://www.ieee.org ISO/IEC C++ ANSI/ISO/IEC 14882:1998 Copyright Ó Microsoft Corporation 1999-2010 All Rights Reserved 529 ... represented using the 32-bit single-precision and 64-bit double-precision IEEE 754 formats The decimal type is a 128-bit data type suitable for financial and monetary calculations C#? ??s bool type is... int[] and int[,] Delegate types User-defined types of the form e.g delegate int D( ) The eight integral types provide support for 8-bit, 16-bit, 32-bit, and 64-bit values in signed or unsigned... Corporation 199 9-2 010 All Rights Reserved Chapter Lexical structure Introduction C# (pronounced “See Sharp”) is a simple, modern, object-oriented, and type-safe programming language C# has its roots

Ngày đăng: 11/05/2021, 03:35

Xem thêm:

Mục lục

    1.6.6.2 Method body and local variables

    1.6.6.3 Static and instance methods

    1.6.6.4 Virtual, override, and abstract methods

    2.4.1 Unicode character escape sequences

    3.5.3 Protected access for instance members

    3.8 Namespace and type names

    4.4.2 Open and closed types

    4.4.3 Bound and unbound types

    5.1.2.1 Instance variables in classes

    5.1.2.2 Instance variables in structs

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN

w