Visual Basic 2015 Reserved Keywords

When writing code, you often define types or declare variables. Types and variables are recognizable via identifiers. An identifier is essentially the name of a type or of a variable and not necessarily a word that makes sense, although it is a good practice to assign human-readable identifiers. For example, an identifier such as DoSomething is much better than DoSmt. There are some words in the Visual Basic lexical grammar that you cannot use as identifiers for your variables because they are reserved for the language.


Naming Conventions for Identifiers

.NET programming principles establish some rules that identifiers must abide by when you’re writing code. For example, the Common Language Specification talks about some naming conventions, which are covered in Chapter 20, “Advanced Language Features.” For now, keep in mind the best practice of making identifiers human readable. Later in the book you’ll learn more specifics about how to name identifiers.


Although the code editor is smart enough to tell you when you are attempting to use a reserved keyword as an identifier, having a reference is practical. Therefore, Table 3.1 lists the Visual Basic 2015 reserved words.

Image
Image

TABLE 3.1 Visual Basic 2015 Reserved Keywords


Using Reserved Words as Identifiers

You can use reserved words as identifiers if you enclose them in a pair of square brackets. For example, New is a reserved word and cannot be used, but [New] is an acceptable identifier name. Although this practice is allowed, however, you should use it only in particular cases because it could lead to confusion, especially if you are not an experienced developer.


Visual Basic has a number of unreserved keywords that are basically words you can use as identifiers but that the programming language keeps for its own usage in particular contexts—usually before or after another keyword. Table 3.2 provides a full list of unreserved keywords. It’s a good idea to always avoid using unreserved keywords as identifiers for your objects or variables.

Image

TABLE 3.2 Visual Basic 2015 Unreserved Keywords


Visual Basic is Case-Insensitive

When writing code, remember that Visual Basic is a case-insensitive programming language. This means that, unlike in C# or C++, in Visual Basic, writing Hello is the same of writing HELLO or hello or heLLo. It’s important to remember this when you’re assigning identifier names.


..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.34.39