DOC

Visual Basic Language Specification 10.0

By Rosa Alexander,2014-10-11 16:53
9 views 0
Visual Basic Language Specification 10.0

The Microsoft

    Visual Basic

    Language Specification

Version 10.0

Paul Vick, Lucian Wischik

    Microsoft Corporation

    Confidential Material Copyright ? Microsoft Corporation 2010. All Rights Reserved.

    Please send corrections, comments, and other feedback to basic@microsoft.com.

Filename: 87287293.docx 2

    The information contained in this document represents the current view of Microsoft Corporation on the issues discussed as of the date of publication. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information presented after the date of publication.

    This Language Specification is for informational purposes only. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS DOCUMENT. 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. Unless otherwise noted, the example companies, organizations, products, domain names, e-mail addresses, logos, people, places and events depicted herein are fictitious, and no association with any real company, organization, product, domain name, email address, logo, person, place or event is intended or should be inferred.

     2010Microsoft Corporation. All rights reserved.

    Microsoft, MS-DOS, Visual Basic, Windows 2000, Windows 95, Windows 98, Windows ME, Windows NT, Windows XP, Windows Vista and Windows are either registered trademarks or trademarks of Microsoft Corporation in the United States and/or other countries. The names of actual companies and products mentioned herein may be the trademarks of their respective owners.

    Table of Contents

1. Introduction .................................................................................................................................................. 1

    1.1 Grammar Notation .................................................................................................................................. 1 1.2 Compatibility ........................................................................................................................................... 2 1.2.1 Kinds of compatibility breaks ............................................................................................................ 2 1.2.2 Impact Criteria.................................................................................................................................. 4 1.2.3 Language deprecation ...................................................................................................................... 5 2. Lexical Grammar ........................................................................................................................................... 7

    2.1 Characters and Lines................................................................................................................................ 7 2.1.1 Line Terminators .............................................................................................................................. 7 2.1.2 Line Continuation ............................................................................................................................. 8 2.1.3 White Space ................................................................................................................................... 10 2.1.4 Comments ...................................................................................................................................... 10 2.2 Identifiers .............................................................................................................................................. 11 2.2.1 Type Characters .............................................................................................................................. 13 2.3 Keywords .............................................................................................................................................. 14 2.4 Literals .................................................................................................................................................. 16 2.4.1 Boolean Literals .............................................................................................................................. 17 2.4.2 Integer Literals ............................................................................................................................... 17 2.4.3 Floating-Point Literals ..................................................................................................................... 18 2.4.4 String Literals.................................................................................................................................. 20 2.4.5 Character Literals ........................................................................................................................... 21 2.4.6 Date Literals ................................................................................................................................... 22 2.4.7 Nothing .......................................................................................................................................... 23 2.5 Separators ............................................................................................................................................. 23 2.6 Operator Characters .............................................................................................................................. 24 3. Preprocessing Directives ............................................................................................................................. 25

    3.1 Conditional Compilation ........................................................................................................................ 25 3.1.1 Conditional Constant Directives ...................................................................................................... 27 3.1.2 Conditional Compilation Directives ................................................................................................. 28 3.2 External Source Directives ..................................................................................................................... 29 Confidential Material Copyright ? Microsoft Corporation 2010. All Rights Reserved. i

    Table of Contents

    3.3 Region Directives ................................................................................................................................... 30 3.4 External Checksum Directives ................................................................................................................ 31 4. General Concepts ........................................................................................................................................ 33

    4.1 Declarations .......................................................................................................................................... 33 4.1.1 Overloading and Signatures ............................................................................................................ 34 4.2 Scope .................................................................................................................................................... 36 4.3 Inheritance ............................................................................................................................................ 37 4.3.1 MustInherit and NotInheritable Classes .......................................................................................... 39

    4.3.2 Interfaces and Multiple Inheritance ................................................................................................ 40 4.3.3 Shadowing ...................................................................................................................................... 43 4.4 Implementation ..................................................................................................................................... 52 4.4.1 Implementing Methods .................................................................................................................. 56 4.5 Polymorphism ....................................................................................................................................... 59 4.5.1 Overriding Methods ....................................................................................................................... 61 4.6 Accessibility ........................................................................................................................................... 67 4.6.1 Constituent Types........................................................................................................................... 70 4.7 Type and Namespace Names ................................................................................................................. 71 4.7.1 Qualified Name Resolution ............................................................................................................. 73 4.7.2 Unqualified Name Resolution ......................................................................................................... 74 4.8 Variables ............................................................................................................................................... 76 4.9 Generic Types and Methods .................................................................................................................. 76 4.9.1 Type Parameters ............................................................................................................................ 78 4.9.2 Type Constraints ............................................................................................................................. 82 4.9.3 Type Parameter Variance ............................................................................................................... 88 5. Attributes .................................................................................................................................................... 93

    5.1 Attribute Classes.................................................................................................................................... 94 5.2 Attribute Blocks ..................................................................................................................................... 97 Confidential Material Copyright ? Microsoft Corporation 2010. All Rights Reserved. ii

    Table of Contents

    5.2.1 Attribute Names ............................................................................................................................. 99 5.2.2 Attribute Arguments..................................................................................................................... 100 6. Source Files and Namespaces ................................................................................................................... 105

    6.1 Program Startup and Termination ....................................................................................................... 106 6.2 Compilation Options ............................................................................................................................ 106 6.2.1 Option Explicit Statement ............................................................................................................. 107 6.2.2 Option Strict Statement ................................................................................................................ 108 6.2.3 Option Compare Statement .......................................................................................................... 108 6.2.4 Integer Overflow Checks ............................................................................................................... 109 6.2.5 Option Infer Statement................................................................................................................. 109 6.3 Imports Statement .............................................................................................................................. 110 6.3.1 Import Aliases .............................................................................................................................. 112 6.3.2 Namespace Imports...................................................................................................................... 115 6.3.3 XML Namespace Imports .............................................................................................................. 117 6.4 Namespaces ........................................................................................................................................ 118 6.4.1 Namespace Declarations .............................................................................................................. 119 6.4.2 Namespace Members ................................................................................................................... 120 7. Types......................................................................................................................................................... 123

    7.1 Value Types and Reference Types ........................................................................................................ 123 7.1.1 Nullable Value Types .................................................................................................................... 125 7.2 Interface Implementation .................................................................................................................... 126 7.3 Primitive Types .................................................................................................................................... 128 7.4 Enumerations ...................................................................................................................................... 130 7.4.1 Enumeration Members ................................................................................................................. 131 7.4.2 Enumeration Values ..................................................................................................................... 131 7.5 Classes................................................................................................................................................. 134 7.5.1 Class Base Specification ................................................................................................................ 136 Confidential Material Copyright ? Microsoft Corporation 2010. All Rights Reserved. iii

    Table of Contents

    7.5.2 Class Members ............................................................................................................................. 137 7.6 Structures ............................................................................................................................................ 138 7.6.1 Structure Members ...................................................................................................................... 139 7.7 Standard Modules ............................................................................................................................... 141 7.7.1 Standard Module Members .......................................................................................................... 142 7.8 Interfaces ............................................................................................................................................ 143 7.8.1 Interface Inheritance .................................................................................................................... 145 7.8.2 Interface Members ....................................................................................................................... 147 7.9 Arrays .................................................................................................................................................. 148 7.10 Delegates .......................................................................................................................................... 151 7.11 Partial types ...................................................................................................................................... 153 7.12 Constructed Types ............................................................................................................................. 156 7.12.1 Open Types and Closed Types ..................................................................................................... 157 7.13 Special Types ..................................................................................................................................... 158 8. Conversions .............................................................................................................................................. 161

    8.1 Implicit and Explicit Conversions .......................................................................................................... 161 8.2 Boolean Conversions ........................................................................................................................... 162 8.3 Numeric Conversions ........................................................................................................................... 162 8.4 Reference Conversions ........................................................................................................................ 164 8.4.1 Reference Variance Conversions ................................................................................................... 165 8.4.2 Anonymous Delegate Conversions ................................................................................................ 167

    8.5 Array Conversions ............................................................................................................................... 167 8.6 Value Type Conversions ....................................................................................................................... 170 8.6.1 Nullable Value Type Conversions .................................................................................................. 174 8.7 String Conversions ............................................................................................................................... 176 8.8 Widening Conversions ......................................................................................................................... 176 8.9 Narrowing Conversions........................................................................................................................ 180 8.10 Type Parameter Conversions ............................................................................................................. 183 Confidential Material Copyright ? Microsoft Corporation 2010. All Rights Reserved. iv

    Table of Contents

    8.11 User-Defined Conversions ................................................................................................................. 184 8.11.1 Most Specific Widening Conversion ............................................................................................ 187 8.11.2 Most Specific Narrowing Conversion .......................................................................................... 188 8.12 Native Conversions ............................................................................................................................ 189 8.13 Dominant Type .................................................................................................................................. 190 9. Type Members .......................................................................................................................................... 191

    9.1 Interface Method Implementation ...................................................................................................... 191 9.2 Methods .............................................................................................................................................. 195 9.2.1 Regular Method Declarations ....................................................................................................... 197 9.2.2 External Method Declarations ...................................................................................................... 199 9.2.3 Overridable Methods ................................................................................................................... 202 9.2.4 Shared Methods ........................................................................................................................... 204 9.2.5 Method Parameters ..................................................................................................................... 205

    9.2.5.1 Value Parameters .................................................................................................................. 206

    9.2.5.2 Reference Parameters ........................................................................................................... 207

    9.2.5.3 Optional Parameters ............................................................................................................. 210

    9.2.5.4 ParamArray Parameters ........................................................................................................ 211 9.2.6 Event Handling ............................................................................................................................. 213 9.2.7 Extension Methods ....................................................................................................................... 215 9.2.8 Partial Methods ............................................................................................................................ 221 9.3 Constructors ........................................................................................................................................ 223 9.3.1 Instance Constructors ................................................................................................................... 224 9.3.2 Shared Constructors ..................................................................................................................... 226 9.4 Events ................................................................................................................................................. 230 9.4.1 Custom Events .............................................................................................................................. 234 9.5 Constants ............................................................................................................................................ 236 9.6 Instance and Shared Variables ............................................................................................................. 238 9.6.1 Read-Only Variables ..................................................................................................................... 241 Confidential Material Copyright ? Microsoft Corporation 2010. All Rights Reserved. v

    Table of Contents

    9.6.2 WithEvents Variables .................................................................................................................... 243 9.6.3 Variable Initializers ....................................................................................................................... 245

    9.6.3.1 Regular Initializers ................................................................................................................. 249

    9.6.3.2 Object Initializers ................................................................................................................... 250

    9.6.3.3 Array-Size Initializers ............................................................................................................. 250 9.6.4 System.MarshalByRefObject Classes ............................................................................................. 252 9.7 Properties............................................................................................................................................ 252 9.7.1 Get Accessor Declarations ............................................................................................................ 262 9.7.2 Set Accessor Declarations ............................................................................................................. 264 9.7.3 Default Properties ........................................................................................................................ 264 9.7.4 Automatically Implemented Properties ........................................................................................ 267 9.8 Operators ............................................................................................................................................ 268 9.8.1 Unary Operators ........................................................................................................................... 270 9.8.2 Binary Operators .......................................................................................................................... 271 9.8.3 Conversion Operators ................................................................................................................... 273 9.8.4 Operator Mapping ........................................................................................................................ 275 10. Statements .............................................................................................................................................. 277

    10.1 Blocks and Labels ............................................................................................................................... 277 10.1.1 Local Variables and Parameters .................................................................................................. 279 10.2 Local Declaration Statements ............................................................................................................ 281 10.2.1 Implicit Local Declarations .......................................................................................................... 286 10.3 With Statement ................................................................................................................................. 287 10.4 SyncLock Statement........................................................................................................................... 288 10.5 Event Statements .............................................................................................................................. 290 10.5.1 RaiseEvent Statement ................................................................................................................. 290 10.5.2 AddHandler and RemoveHandler Statements ............................................................................. 292

    10.6 Assignment Statements ..................................................................................................................... 293 10.6.1 Regular Assignment Statements ................................................................................................. 293 Confidential Material Copyright ? Microsoft Corporation 2010. All Rights Reserved. vi

    Table of Contents

    10.6.2 Compound Assignment Statements ............................................................................................ 296 10.6.3 Mid Assignment Statement ........................................................................................................ 297 10.7 Invocation Statements ....................................................................................................................... 298 10.8 Conditional Statements ..................................................................................................................... 298 10.8.1 If...Then...Else Statements .......................................................................................................... 298 10.8.2 Select Case Statements ............................................................................................................... 301 10.9 Loop Statements ............................................................................................................................... 303 10.9.1 While...End While and Do...Loop Statements .............................................................................. 303

    10.9.2 For...Next Statements ................................................................................................................. 305 10.9.3 For Each...Next Statements......................................................................................................... 307 10.10 Exception-Handling Statements ....................................................................................................... 312 10.10.1 Structured Exception-Handling Statements............................................................................... 313

    10.10.1.1 Finally Blocks ..................................................................................................................... 314

    10.10.1.2 Catch Blocks ...................................................................................................................... 314

    10.10.1.3 Throw Statement ............................................................................................................... 316 10.10.2 Unstructured Exception-Handling Statements .......................................................................... 317

    10.10.2.1 Error Statement ................................................................................................................. 318

    10.10.2.2 On Error Statement ........................................................................................................... 318

    10.10.2.3 Resume Statement ............................................................................................................ 319 10.11 Branch Statements .......................................................................................................................... 320 10.12 Array-Handling Statements .............................................................................................................. 322 10.12.1 ReDim Statement ..................................................................................................................... 322 10.12.2 Erase Statement ....................................................................................................................... 324 10.13 Using statement .............................................................................................................................. 324 11. Expressions ............................................................................................................................................. 327

    11.1 Expression Classifications .................................................................................................................. 327 11.1.1 Expression Reclassification ......................................................................................................... 329 11.2 Constant Expressions ......................................................................................................................... 333 Confidential Material Copyright ? Microsoft Corporation 2010. All Rights Reserved. vii

    Table of Contents

    11.3 Late-Bound Expressions ..................................................................................................................... 335 11.4 Simple Expressions ............................................................................................................................ 337 11.4.1 Literal Expressions ...................................................................................................................... 337 11.4.2 Parenthesized Expressions .......................................................................................................... 338 11.4.3 Instance Expressions ................................................................................................................... 338 11.4.4 Simple Name Expressions ........................................................................................................... 340 11.4.5 AddressOf Expressions................................................................................................................ 343 11.5 Type Expressions ............................................................................................................................... 343 11.5.1 GetType Expressions ................................................................................................................... 344 11.5.2 TypeOf...Is Expressions ............................................................................................................... 345 11.5.3 Is Expressions ............................................................................................................................. 346 11.5.4 GetXmlNamespace Expressions .................................................................................................. 346 11.6 Member Access Expressions .............................................................................................................. 347 11.6.1 Identical Type and Member Names ............................................................................................ 351 11.6.2 Default Instances ........................................................................................................................ 352

    11.6.2.1 Default Instances and Type Names ...................................................................................... 354

    11.6.2.2 Group Classes ...................................................................................................................... 355 11.6.3 Extension Method Collection ...................................................................................................... 357 11.7 Dictionary Member Access Expressions ............................................................................................. 363 11.8 Invocation Expressions ...................................................................................................................... 364 11.8.1 Overloaded Method Resolution .................................................................................................. 366

    11.8.1.1 Applicability......................................................................................................................... 374

    11.8.1.2 Genericity ............................................................................................................................ 376 11.8.2 Applicable Methods .................................................................................................................... 379 11.8.3 Passing Parameters .................................................................................................................... 381 11.8.4 Conditional Methods .................................................................................................................. 382 11.8.5 Type Argument Inference ........................................................................................................... 382 11.9 Index Expressions .............................................................................................................................. 386 11.10 New Expressions .............................................................................................................................. 387 Confidential Material Copyright ? Microsoft Corporation 2010. All Rights Reserved. viii

Report this document

For any questions or suggestions please email
cust-service@docsford.com