Creating User-Defined Value Types

Let's start by asking a fundamental question: What criteria does the CLR use to determine whether a type is a value type or a reference type? The CLR uses a simple rule: Every type that inherits either directly or indirectly from System.ValueType is a value type. Any type that does not follow this rule is a reference type.

Figure 10.1 shows how value types fit into the CTS's inheritance hierarchy. Many system-provided primitive types such a Boolean, Int32, Double, and DateTime are defined as value types. Notice that all enumerations and structures are defined as value types as well because they inherit from ValueType.

Figure 10.1. All types that inherit from System.Value type are considered value types.

Visual ...

Get Building Applications and Components with Visual Basic .NET now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.