.NET Framework Class Library
Nullable Class

Supports a value type that can be assigned . This class cannot be inherited.

Namespace:   System
Assembly:  mscorlib (in mscorlib.dll)
Syntax
<[%$TOPIC/fs5xdbk8_en-us_VS_110_2_0_0_0_0%](True)> _
Public NotInheritable Class Nullable
[[%$TOPIC/fs5xdbk8_en-us_VS_110_2_0_1_0_0%](true)]
public static class Nullable
[[%$TOPIC/fs5xdbk8_en-us_VS_110_2_0_2_0_0%](true)]
public ref class Nullable abstract sealed
[<[%$TOPIC/fs5xdbk8_en-us_VS_110_2_0_3_0_0%]>]
[<[%$TOPIC/fs5xdbk8_en-us_VS_110_2_0_3_0_1%]>]
[<[%$TOPIC/fs5xdbk8_en-us_VS_110_2_0_3_0_2%](true)>]
type Nullable =  class end

The Nullable type exposes the following members.

Methods
  NameDescription
Public method Static member Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps CompareTCompares the relative values of two NullableT objects.
Public method Static member Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps EqualsTIndicates whether two specified NullableT objects are equal.
Public method Static member Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps GetUnderlyingTypeReturns the underlying type argument of the specified nullable type.
Top
Remarks

A type is said to be nullable if it can be assigned a value or can be assigned , 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 .

The Nullable class provides complementary support for the NullableT 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 NullableT object, not the NullableT object itself. That is, if the HasValue property is true, the contents of the Value property is boxed. If the HasValue property is false, is boxed. When the underlying value of a nullable type is unboxed, the common language runtime creates a new NullableT structure initialized to the underlying value.

Version Information

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

.NET for Windows Store apps

Supported in: Windows 8

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone Silverlight 8.1, Windows Phone Silverlight 8
Platforms

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, 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.

Thread Safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.