Nullable Class
Supports a value type that can be assigned a null reference (Nothing in Visual Basic). This class cannot be inherited.
Namespace: System
Assembly: mscorlib (in mscorlib.dll)
The Nullable type exposes the following members.
| Name | Description | |
|---|---|---|
![]() ![]() ![]() ![]() ![]() | Compare(T) | Compares the relative values of two Nullable(T) objects. |
![]() ![]() ![]() ![]() ![]() | Equals(T) | Indicates whether two specified Nullable(T) objects are equal. |
![]() ![]() ![]() ![]() ![]() | GetUnderlyingType | Returns the underlying type argument of the specified nullable type. |
A type is said to be nullable if it can be assigned a value or can be assigned a null reference (Nothing in Visual Basic), which means the type has no value whatsoever. By default, all reference types, such as String, are nullable, but all value types, such as Int32, are not.
In C# and Visual Basic, you mark a value type as nullable by using the ? notation after the value type. For example, int? in C# or Integer? in Visual Basic declares an integer value type that can be assigned a null reference (Nothing in Visual Basic).
The Nullable class provides complementary support for the Nullable(T) structure. The Nullable class supports obtaining the underlying type of a nullable type, and comparison and equality operations on pairs of nullable types whose underlying value type does not support generic comparison and equality operations.
Boxing and Unboxing
When a nullable type is boxed, the common language runtime automatically boxes the underlying value of the Nullable(T) object, not the Nullable(T) object itself. That is, if the HasValue property is true, the contents of the Value property is boxed. If the HasValue property is false, a null reference (Nothing in Visual Basic) is boxed. When the underlying value of a nullable type is unboxed, the common language runtime creates a new Nullable(T) structure initialized to the underlying value.
Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
.gif?cs-save-lang=1&cs-lang=fsharp)
.gif?cs-save-lang=1&cs-lang=fsharp)
.gif?cs-save-lang=1&cs-lang=fsharp)
.png?cs-save-lang=1&cs-lang=fsharp)
.png?cs-save-lang=1&cs-lang=fsharp)