Types

Types in Visual Basic .NET are divided into two categories: value types and reference types . Value types minimize memory overhead and maximize speed of access, but they lack some features of a fully object-oriented design (such as inheritance). Reference types give full access to object-oriented features, but they impose some memory and speed overhead for managing and accessing objects. When a variable holds a value type, the data itself is stored in the variable. When a variable holds a reference type, a reference to the data (also known as a pointer ) is stored in the variable, and the data itself is stored somewhere else. Visual Basic .NET’s primitive types include both value types and reference types (see “Fundamental Types” in this section). For extending the type system, Visual Basic .NET provides syntax for defining both new value types and new reference types (see “Custom Types” later in this section).

All reference types derive from the Object type. To unify the type system, value types can be treated as reference types when needed. This means that all types can derive from the Object type. Treating value types as reference types (a process known as boxing ) is addressed later in this chapter, in Section 2.16.

Fundamental Types

Visual Basic .NET has several built-in types. Each of these types is an alias for a type supplied by the .NET architecture. Because Visual Basic .NET types are equivalent to the corresponding underlying .NET-supplied types, there are no ...

Get Programming Visual Basic .NET now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.