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 |
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:
123I is a literal of type Integer.
Visual Basic .NET defines the following primitive types:
0. 0.
0D. # 01/01/0001 12:00:00AM #.
ChrW(0). PrimitiveTypeName ::= NumericTypeName | Boolean | Date | Char | String NumericTypeName ::= IntegralTypeName | FloatingPointTypeName | Decimal IntegralTypeName ::= Byte | Short | Integer | Long FloatingPointTypeName ::= Single | Double
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.
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.