Value Types and Reference Types

There are two main categories of types that are managed by the common language runtime: value types and reference types. The difference between them is that reference types, such as objects, are stored on a portion of memory in the computer called the heap, whereas value types, such as numeric data types, are stored on another portion of memory called the stack.

Value types include structures, the numeric data types (Byte, Short, Integer, Long, Single, Double), enumerations, Boolean, Char, and Date. Reference types include classes, delegates, arrays, and Strings, and they can be accessed only through a reference to their location. When you create a variable for a value type without assigning it a value, the type is automatically initialized to a default value.

Table 3.1 lists some common data types, shows how they map to the System namespace in the .NET class library, and lists their default values. When you create a reference type variable, however, its value defaults to Nothing.

Table 3.1. Default Value for Data Types

Data Type

Namespace Map

Default Value

Byte

System.Byte

0

Short

System.Int16

0

Integer

System.Int32

0

Long

System.Int64

(continues)

Table 3.1. Default Value for Data Types (Continued)

Data Type

Namespace Map

Default Value

Single

System.Single

0

Double

System.Double

0

Decimal

System.Decimal

0D

Boolean

System.Boolean

False

Date

System.DateTime

01/01/0001 12:00:00AM

String

System.String

Nothing

0 0

Post a comment