7.3 Primitive Types

7.1 Value Types and Reference Types | 7.6 Structures | 7.5 Classes | 7.7 Standard Modules | 7.8 Interfaces | 7.9 Arrays | 7.10 Delegates | 11.2 Constant Expressions | Data Type Summary (Visual Basic Language Reference) | Value Types and Reference Types (Visual Basic Language Concepts)

The primitive types are identified through keywords, which are aliases for predefined types in the System namespace. A primitive type is completely indistinguishable from the type it aliases: writing the reserved word Byte is exactly the same as writing System.Byte.

Because a primitive type aliases a regular type, every primitive type has members. For example, Integer has the members declared in System.Int32. Literals can be treated as instances of their corresponding types.

The primitive types differ from other structure types in that they permit certain additional operations:

Visual Basic .NET defines the following primitive types:

PrimitiveTypeName ::= NumericTypeName | Boolean | Date | Char | String
NumericTypeName ::= IntegralTypeName | FloatingPointTypeName | Decimal
IntegralTypeName ::= Byte | Short | Integer | Long
FloatingPointTypeName ::= Single | Double

Composite Data Types

See Also

Arrays | Structures: Your Own Data Types | Data Types as Classes and Structures

In addition to the elementary data types Visual Basic supplies, you can also assemble items of different types to create composite data types such as structures, arrays, and classes. You can build composite data types from elementary types and from other composite types. For example, you can define an array of structure elements, or a structure with array members.

A composite type is different from the data type of any of its components. For example, an array of Integer elements is not of the Integer data type.

There is no single data type comprising all structures. Instead, each definition of a structure represents a unique data type. The same uniqueness is true for classes.

There is also no single data type comprising all arrays. The data type of a particular instance of an array is determined by:

In particular, the length of a given dimension is not part of the instance's data type. This is illustrated in the following example:

Dim A As Byte( ) = New Byte(12) {}
Dim B As Byte( ) = New Byte(100) {}
Dim C As Short( ) = New Short(100) {}
Dim D As Short( , )
Dim E As Short( , ) = New Short(4, 10) {}

In the preceding example, array variables A and B are considered to be of the same data type, even though they are initialized to different lengths. Array variables B and C are not of the same type because their element types are different. C and D are not of the same type because their ranks are different. D and E have the same type because their ranks and element types are the same, even though D is not yet initialized.

 

Arrays

When you use arrays, you can refer to multiple variables by the same name, using a number called an index or subscript to distinguish them from one another. Arrays can shorten and simplify your code, allowing you to create loops that deal efficiently with any number of elements.

In This Section

Arrays Overview
Explains what arrays are and how they work, including information on dimensionality, size, and type.
Array Usage
Provides information on how to use arrays, including multidimensional arrays.
Declaring Array Variables
Provides information on using Dim, Public, Protected, Friend, Protected Friend, and Private.
Advanced Features of Arrays
Describes assigning the contents of one array to another, and returning an array from a function.
Arrays of Arrays
Describes creating an Object array and populating it with other arrays of different data types.
Collections as an Alternative to Arrays
Provides information on storing items in a collection instead of an array, a practice that can be more efficient in some scenarios.

Related Sections

Language Changes in Visual Basic
Provides an overview of the new features in Visual Basic .NET.
Object-Oriented Programming in Visual Basic
Covers object-oriented programming basics.