This documentation is archived and is not being maintained.

Declared Element Names

Every declared element has a name, also called an identifier, which is what the code uses to refer to it.

An element name:

  • Must begin with an alphabetic character or an underscore (_).
  • Must contain only alphabetic characters, decimal digits, and underscores.
  • Must contain at least one alphabetic character or decimal digit it if begins with an underscore.
  • Must not be more than 1023 characters long.

The following example shows some valid and invalid element names:

aB123__45   ' Valid. 
_567   ' Valid. 
_   ' Invalid - consists of an underscore only. 
12ABC   ' Invalid - begins with a decimal digit. 
xyz$wv   ' Invalid - contains an identifier type character. 
Note   The length limit of 1023 characters also applies to a fully qualified name, such as: OuterNamespace.MiddleNamespace.InnerNamespace.ThisClass.ThisElement. The entire preceding string is limited to 1023 characters.

Escaped Names

Generally, an element name must not match any of the keywords reserved by Visual Basic, such as Case or Friend. However, you can define an escaped name, which is enclosed by brackets ([ ]). An escaped name can match any Visual Basic keyword, since the brackets remove any ambiguity. You also use the brackets when you refer to the name later in your code.

Case Sensitivity in Names

Names in Visual Basic .NET are case insensitive. This means that when the compiler compares two names that differ in alphabetic case only, it interprets them as the same name. For example, ABC and abc are considered to refer to the same declared element.

However, the common language runtime uses case-sensitive binding. Therefore, when you produce an assembly or a DLL and make it available to other assemblies, your names are no longer case insensitive. For example, if you define a class with an element called ABC, and other assemblies make use of your class through the common language runtime, they must refer to the element as ABC. If you subsequently recompile your class and change the element's name to abc, the other assemblies using your class can no longer access that element. Therefore, when you release an updated version of an assembly, you should not change the alphabetic case of any public elements.

Comparison of names is also independent of locale; that is, if two names match in one locale, they are guaranteed to match in all locales.

See Also

Declared Element Characteristics | Declared Element Reference | Declaration Statements

Show: