Visual Basic Language Specification

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 14

4.

1.

Copyright Microsoft Corporation . All Rights Reserved.

Inheritance

Introduction

2. The Microsoft Visual Basic programming language is a high-level


programming language for the Microsoft .NET Framework. Although it is
designed to be an approachable and easy-to-learn language, it is also
powerful enough to satisfy the needs of experienced programmers. The
Visual Basic programming language has a syntax that is similar to English,
which promotes the clarity and readability of Visual Basic code. Wherever
possible, meaningful words or phrases are used instead of abbreviations,
acronyms, or special characters. Extraneous or unneeded syntax is
generally allowed but not required.
3. The Visual Basic programming language can be either a strongly typed or a
loosely typed language. Loose typing defers much of the burden of type
checking until a program is already running. This includes not only type
checking of conversions but also of method calls, meaning that the binding
of a method call can be deferred until run-time. This is useful when building
prototypes or other programs in which speed of development is more
important than execution speed. The Visual Basic programming language
also provides strongly typed semantics that performs all type checking at
compile-time and disallows run-time binding of method calls. This
guarantees maximum performance and helps ensure that type conversions
are correct. This is useful when building production applications in which
speed of execution and execution correctness is important.
4. This document describes the Visual Basic language. It is meant to be a
complete language description rather than a language tutorial or a user's
reference manual.

4.1 Grammar Notation


5. This specification describes two grammars: a lexical grammar and a syntactic
grammar. The lexical grammar defines how characters can be combined to
form tokens; the syntactic grammar defines how the tokens can be
combined to form Visual Basic programs. There are also several secondary
grammars used for preprocessing operations like conditional compilation.
6. Note The grammars in this specification are designed to be human
readable, not formal (that is, usable by LEX or YACC).
7. All of the grammars use a modified BNF notation, which consists of a set of
productions made up of terminal and nonterminal names. A terminal name

4.3

The Microsoft
Visual Basic
Language Specification
Version 11.0

Paul Vick, Lucian Wischik


Microsoft Corporation

Inheritance

Filename: 341522484 3

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.
2012 Microsoft 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 Grammar Notation....................................................................................................
1.2 Compatibility.............................................................................................................
1.2.1 Kinds of compatibility breaks..............................................................................
1.2.2 Impact Criteria....................................................................................................
1.2.3 Language deprecation........................................................................................
2. Lexical Grammar.......................................................................................
2.1 Characters and Lines.................................................................................................
2.1.1 Line Terminators.................................................................................................
2.1.2 Line Continuation................................................................................................
2.1.3 White Space........................................................................................................
2.1.4 Comments..........................................................................................................
2.2 Identifiers..................................................................................................................
2.2.1 Type Characters..................................................................................................
2.3 Keywords...................................................................................................................
2.4 Literals....................................................................................................................
2.4.1 Boolean Literals................................................................................................
2.4.2 Integer Literals..................................................................................................
2.4.3 Floating-Point Literals.......................................................................................
2.4.4 String Literals....................................................................................................
2.4.5 Character Literals.............................................................................................
2.4.6 Date Literals.....................................................................................................
2.4.7 Nothing.............................................................................................................
2.5 Separators...............................................................................................................
2.6 Operator Characters................................................................................................
3. Preprocessing Directives.........................................................................
3.1 Conditional Compilation..........................................................................................
3.1.1 Conditional Constant Directives........................................................................
3.1.2 Conditional Compilation Directives...................................................................
3.2 External Source Directives......................................................................................

Filename: 341522484 5

3.3 Region Directives....................................................................................................


3.4 External Checksum Directives.................................................................................
4. General Concepts....................................................................................
4.1 Declarations............................................................................................................
4.1.1 Overloading and Signatures..............................................................................
4.2 Scope......................................................................................................................
4.3 Inheritance..............................................................................................................
4.3.1 MustInherit and NotInheritable Classes............................................................
4.3.2 Interfaces and Multiple Inheritance...................................................................
4.3.3 Shadowing........................................................................................................
4.4 Implementation.......................................................................................................
4.4.1 Implementing Methods.....................................................................................
4.5 Polymorphism..........................................................................................................
4.5.1 Overriding Methods..........................................................................................
4.6 Accessibility.............................................................................................................
4.6.1 Constituent Types.............................................................................................
4.7 Type and Namespace Names..................................................................................
4.7.1 Qualified Name Resolution for namespaces and types.....................................
4.7.2 Unqualified Name Resolution for namespaces and types.................................
4.8 Variables..................................................................................................................
4.9 Generic Types and Methods....................................................................................
4.9.1 Type Parameters...............................................................................................
4.9.2 Type Constraints...............................................................................................
4.9.3 Type Parameter Variance..................................................................................
5. Attributes...............................................................................................
5.1 Attribute Classes.....................................................................................................
5.2 Attribute Blocks.......................................................................................................
5.2.1 Attribute Names................................................................................................
5.2.2 Attribute Arguments.........................................................................................
6. Source Files and Namespaces..................................................................

6.1 Program Startup and Termination............................................................................


6.2 Compilation Options................................................................................................
6.2.1 Option Explicit Statement.................................................................................
6.2.2 Option Strict Statement....................................................................................
6.2.3 Option Compare Statement..............................................................................
6.2.4 Integer Overflow Checks...................................................................................
6.2.5 Option Infer Statement.....................................................................................
6.3 Imports Statement..................................................................................................
6.3.1 Import Aliases...................................................................................................
6.3.2 Namespace Imports..........................................................................................
6.3.3 XML Namespace Imports..................................................................................
6.4 Namespaces............................................................................................................
6.4.1 Namespace Declarations..................................................................................
6.4.2 Namespace Members.......................................................................................
7. Types......................................................................................................
7.1 Value Types and Reference Types............................................................................
7.1.1 Nullable Value Types.........................................................................................
7.2 Interface Implementation........................................................................................
7.3 Primitive Types........................................................................................................
7.4 Enumerations..........................................................................................................
7.4.1 Enumeration Members......................................................................................
7.4.2 Enumeration Values..........................................................................................
7.5 Classes....................................................................................................................
7.5.1 Class Base Specification...................................................................................
7.5.2 Class Members..................................................................................................
7.6 Structures................................................................................................................
7.6.1 Structure Members...........................................................................................
7.7 Standard Modules....................................................................................................
7.7.1 Standard Module Members...............................................................................
7.8 Interfaces................................................................................................................
7.8.1 Interface Inheritance.........................................................................................
7.8.2 Interface Members............................................................................................
7.9 Arrays......................................................................................................................
7.10 Delegates..............................................................................................................
7.11 Partial types..........................................................................................................
7.12 Constructed Types...............................................................................................
7.12.1 Open Types and Closed Types.......................................................................
7.13 Special Types.......................................................................................................
8. Conversions..........................................................................................
8.1 Implicit and Explicit Conversions...........................................................................

Filename: 341522484 7

8.2 Boolean Conversions.............................................................................................


8.3 Numeric Conversions............................................................................................
8.4 Reference Conversions..........................................................................................
8.4.1 Reference Variance Conversions.....................................................................
8.4.2 Anonymous Delegate Conversions.................................................................
8.5 Array Conversions.................................................................................................
8.6 Value Type Conversions.........................................................................................
8.6.1 Nullable Value Type Conversions.....................................................................
8.7 String Conversions................................................................................................
8.8 Widening Conversions...........................................................................................
8.9 Narrowing Conversions..........................................................................................
8.10 Type Parameter Conversions...............................................................................
8.11 User-Defined Conversions...................................................................................
8.11.1 Most Specific Widening Conversion..............................................................
8.11.2 Most Specific Narrowing Conversion.............................................................
8.12 Native Conversions.............................................................................................
8.13 Dominant Type....................................................................................................
9. Type Members.......................................................................................
9.1 Interface Method Implementation.........................................................................
9.2 Methods................................................................................................................
9.2.1 Regular, Async and Iterator Method Declarations...........................................
9.2.2 External Method Declarations.........................................................................
9.2.3 Overridable Methods.......................................................................................
9.2.4 Shared Methods..............................................................................................
9.2.5 Method Parameters.........................................................................................
9.2.5.1 Value Parameters.....................................................................................
9.2.5.2 Reference Parameters..............................................................................
9.2.5.3 Optional Parameters.................................................................................
9.2.5.4 ParamArray Parameters............................................................................
9.2.6 Event Handling...............................................................................................
9.2.7 Extension Methods..........................................................................................
9.2.8 Partial Methods...............................................................................................

9.3 Constructors..........................................................................................................
9.3.1 Instance Constructors.....................................................................................
9.3.2 Shared Constructors.......................................................................................
9.4 Events...................................................................................................................
9.4.1 Custom Events................................................................................................
9.5 Constants..............................................................................................................
9.6 Instance and Shared Variables..............................................................................
9.6.1 Read-Only Variables........................................................................................
9.6.2 WithEvents Variables......................................................................................
9.6.3 Variable Initializers..........................................................................................
9.6.3.1 Regular Initializers....................................................................................
9.6.3.2 Object Initializers......................................................................................
9.6.3.3 Array-Size Initializers................................................................................
9.6.4 System.MarshalByRefObject Classes..............................................................
9.7 Properties..............................................................................................................
9.7.1 Get Accessor Declarations..............................................................................
9.7.2 Set Accessor Declarations...............................................................................
9.7.3 Default Properties...........................................................................................
9.7.4 Automatically Implemented Properties...........................................................
9.7.5 Iterator Properties...........................................................................................
9.8 Operators..............................................................................................................
9.8.1 Unary Operators.............................................................................................
9.8.2 Binary Operators.............................................................................................
9.8.3 Conversion Operators.....................................................................................
9.8.4 Operator Mapping...........................................................................................
10. Statements..........................................................................................
10.1 Control Flow........................................................................................................
10.1.1 Regular Methods...........................................................................................
10.1.2 Iterator Methods...........................................................................................
10.1.3 Async methods.............................................................................................
10.1.4 Blocks and Labels.........................................................................................
10.1.5 Local Variables and Parameters....................................................................
10.2 Local Declaration Statements.............................................................................
10.2.1 Implicit Local Declarations............................................................................
10.3 With Statement...................................................................................................
10.4 SyncLock Statement............................................................................................
10.5 Event Statements................................................................................................
10.5.1 RaiseEvent Statement..................................................................................
10.5.2 AddHandler and RemoveHandler Statements...............................................
10.6 Assignment Statements......................................................................................
10.6.1 Regular Assignment Statements...................................................................

Filename: 341522484 9

10.6.2 Compound Assignment Statements..............................................................


10.6.3 Mid Assignment Statement...........................................................................
10.7 Invocation Statements........................................................................................
10.8 Conditional Statements.......................................................................................
10.8.1 If...Then...Else Statements............................................................................
10.8.2 Select Case Statements................................................................................
10.9 Loop Statements.................................................................................................
10.9.1 While...End While and Do...Loop Statements................................................
10.9.2 For...Next Statements...................................................................................
10.9.3 For Each...Next Statements..........................................................................
10.10 Exception-Handling Statements........................................................................
10.10.1 Structured Exception-Handling Statements................................................
10.10.1.1 Finally Blocks........................................................................................
10.10.1.2 Catch Blocks.........................................................................................
10.10.1.3 Throw Statement..................................................................................
10.10.2 Unstructured Exception-Handling Statements............................................
10.10.2.1 Error Statement....................................................................................
10.10.2.2 On Error Statement..............................................................................
10.10.2.3 Resume Statement...............................................................................
10.11 Branch Statements............................................................................................
10.12 Array-Handling Statements...............................................................................
10.12.1 ReDim Statement........................................................................................
10.12.2 Erase Statement.........................................................................................
10.13 Using statement................................................................................................
10.14 Await Statements..............................................................................................
10.15 Yield Statements...............................................................................................
11. Expressions.........................................................................................
11.1 Expression Classifications...................................................................................
11.1.1 Expression Reclassification...........................................................................
11.2 Constant Expressions..........................................................................................
11.3 Late-Bound Expressions......................................................................................
11.4 Simple Expressions.............................................................................................

11.4.1 Literal Expressions........................................................................................


11.4.2 Parenthesized Expressions............................................................................
11.4.3 Instance Expressions....................................................................................
11.4.4 Simple Name Expressions.............................................................................
11.4.5 AddressOf Expressions..................................................................................
11.5 Type Expressions.................................................................................................
11.5.1 GetType Expressions.....................................................................................
CommaList ::= ...........................................................Comma | CommaList
225
11.5.2 TypeOf...Is Expressions..................................................................................
11.5.3 Is Expressions...............................................................................................
11.5.4 GetXmlNamespace Expressions....................................................................
11.6 Member Access Expressions...............................................................................
11.6.1 Identical Type and Member Names...............................................................
11.6.2 Default Instances..........................................................................................
11.6.2.1 Default Instances and Type Names........................................................
11.6.2.2 Group Classes.........................................................................................
11.6.3 Extension Method Collection.........................................................................
11.7 Dictionary Member Access Expressions..............................................................
11.8 Invocation Expressions........................................................................................
11.8.1 Overloaded Method Resolution.....................................................................
11.8.1.1 Specificity of members/types given an argument list.............................
11.8.1.2 Genericity...............................................................................................
11.8.1.3 Depth of genericity.................................................................................
11.8.2 Applicability To Argument List.......................................................................
11.8.3 Passing Arguments, and Picking Arguments for Optional Parameters
................................................................................................................................
11.8.4 Conditional Methods.....................................................................................
11.8.5 Type Argument Inference..............................................................................
11.9 Index Expressions................................................................................................
11.10 New Expressions...............................................................................................
11.10.1 Object-Creation Expressions.......................................................................
11.10.2 Array Expressions.......................................................................................
11.10.2.1 Array creation expressions...................................................................
11.10.2.2 Array Literals........................................................................................
11.10.3 Delegate-Creation Expressions...................................................................
11.10.4 Anonymous Object-Creation Expressions....................................................
11.11 Cast Expressions...............................................................................................
11.12 Operator Expressions........................................................................................
11.12.1 Operator Precedence and Associativity......................................................
11.12.2 Object Operands.........................................................................................
11.12.3 Operator Resolution....................................................................................

Filename: 341522484 11

11.13 Arithmetic Operators.........................................................................................


11.13.1 Unary Plus Operator....................................................................................
11.13.2 Unary Minus Operator.................................................................................
11.13.3 Addition Operator.......................................................................................
11.13.4 Subtraction Operator..................................................................................
11.13.5 Multiplication Operator...............................................................................
11.13.6 Division Operators......................................................................................
11.13.7 Mod Operator..............................................................................................
11.13.8 Exponentiation Operator.............................................................................
11.14 Relational Operators..........................................................................................
11.15 Like Operator.....................................................................................................
11.16 Concatenation Operator....................................................................................
11.17 Logical Operators..............................................................................................
11.17.1 Short-circuiting Logical Operators...............................................................
11.18 Shift Operators..................................................................................................
11.19 Boolean Expressions.........................................................................................
11.20 Lambda Expressions..........................................................................................
11.20.1 Closures......................................................................................................
11.21 Query Expressions.............................................................................................
11.21.1 Range Variables..........................................................................................
11.21.2 Queryable Types.........................................................................................
11.21.3 Default Query Indexer.................................................................................
11.21.4 From Query Operator..................................................................................
11.21.5 Join Query Operator....................................................................................
11.21.6 Let Query Operator.....................................................................................
11.21.7 Select Query Operator................................................................................
11.21.8 Distinct Query Operator..............................................................................
11.21.9 Where Query Operator................................................................................
11.21.10 Partition Query Operators.........................................................................
11.21.11 Order By Query Operator..........................................................................
11.21.12 Group By Query Operator.........................................................................
11.21.13 Aggregate Query Operator.......................................................................
11.21.14 Group Join Query Operator........................................................................

11.22 Conditional Expressions....................................................................................


11.23 XML Literal Expressions.....................................................................................
11.23.1 Lexical rules................................................................................................
11.23.2 Embedded expressions...............................................................................
11.23.3 XML Documents..........................................................................................
11.23.4 XML Elements.............................................................................................
11.23.5 XML Namespaces........................................................................................
11.23.6 XML Processing Instructions........................................................................
11.23.7 XML Comments...........................................................................................
11.23.8 CDATA sections...........................................................................................
11.24 XML Member Access Expressions......................................................................
11.25 Await Operator..................................................................................................
12. Documentation Comments....................................................................
12.1 Documentation Comment Format.......................................................................
12.2 Recommended tags............................................................................................
12.2.1 <c>..............................................................................................................
12.2.2 <code>.........................................................................................................
12.2.3 <example>...................................................................................................
12.2.4 <exception>.................................................................................................
12.2.5 <include>.....................................................................................................
12.2.6 <list>............................................................................................................
12.2.7 <para>.........................................................................................................
12.2.8 <param>......................................................................................................
12.2.9 <paramref>..................................................................................................
12.2.10 <permission>.............................................................................................
12.2.11 <remarks>.................................................................................................
12.2.12 <returns>...................................................................................................
12.2.13 <see>.........................................................................................................
12.2.14 <seealso>..................................................................................................
12.2.15 <summary>...............................................................................................
12.2.16 <typeparam>.............................................................................................
12.2.17 <value>......................................................................................................
12.3 ID Strings.............................................................................................................
12.3.1 ID string examples........................................................................................
12.4 Documentation comments example....................................................................
13. Grammar Summary..............................................................................
13.1 Lexical Grammar.................................................................................................
13.1.1 Characters and Lines....................................................................................
13.1.2 Identifiers......................................................................................................
13.1.3 Keywords......................................................................................................

Filename: 341522484 13

13.1.4 Literals..........................................................................................................
13.2 Preprocessing Directives.....................................................................................
13.2.1 Conditional Compilation................................................................................
13.2.2 External Source Directives............................................................................
13.2.3 Region Directives..........................................................................................
13.2.4 External Checksum Directives......................................................................
13.3 Syntactic Grammar.............................................................................................
13.3.1 Attributes......................................................................................................
13.3.2 Source Files and Namespaces.......................................................................
13.3.3 Types.............................................................................................................
13.3.4 Type Members...............................................................................................
13.3.5 Statements...................................................................................................
13.3.6 Expressions...................................................................................................
14. Change List.........................................................................................
14.1 Version 7.1 to Version 8.0....................................................................................
14.1.1 Major changes...............................................................................................
14.1.2 Minor changes..............................................................................................
14.1.3 Clarifications/Errata......................................................................................
14.1.4 Miscellaneous...............................................................................................
14.2 Version 8.0 to Version 8.0 (2nd Edition)................................................................
14.2.1 Minor changes..............................................................................................
14.2.2 Clarifications/Errata......................................................................................
14.2.3 Miscellaneous...............................................................................................
14.3 Version 8.0 (2nd Edition) to Version 9.0................................................................
14.3.1 Major Changes..............................................................................................
14.3.2 Minor Changes..............................................................................................
14.3.3 Clarifications/Errata......................................................................................
14.3.4 Miscellaneous...............................................................................................
14.4 Version 9.0 to Version 10.0..................................................................................
14.4.1 Major Changes..............................................................................................
14.4.2 Minor Changes..............................................................................................
14.4.3 Clarifications/Errata......................................................................................

14.5 Version 10.0 to Version 11.0................................................................................


14.5.1 Major Changes..............................................................................................
14.5.2 Minor Changes..............................................................................................
14.5.3 Clarifications/Errata......................................................................................

You might also like