mscorlib 2.0.0.0 4.0.0.0 DefaultConstructorConstraint NotNullableValueTypeConstraint System.ValueType System.ValueType System.Diagnostics.DebuggerStepThrough To be added.

A type is said to be nullable if it can be assigned a value or can be assigned null, which means the type has no value whatsoever. By default, all reference types, such as , are nullable, but all value types, such as , 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 null.

The structure supports using only a value type as a nullable type because reference types are nullable by design.

The class provides complementary support for the structure. The 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.

## Fundamental Properties

The two fundamental members of the structure are the and properties. If the property for a object is true, the value of the object can be accessed with the property. If the property is false, the value of the object is undefined and an attempt to access the property throws an .

## Boxing and Unboxing

When a nullable type is boxed, the common language runtime automatically boxes the underlying value of the object, not the object itself. That is, if the property is true, the contents of the property is boxed. When the underlying value of a nullable type is unboxed, the common language runtime creates a new structure initialized to the underlying value.

If the HasValue property of a nullable type is false, the result of a boxing operation is null. Consequently, if a boxed nullable type is passed to a method that expects an object argument, that method must be prepared to handle the case where the argument is null. When null is unboxed into a nullable type, the common language runtime creates a new structure and initializes its HasValue property to false.

## net_v451 and Windows Runtime Components

Starting with the net_v451, you can include a type as a member of a structure exported in a WinMD library. Previously, this was not supported.

Represents a value type that can be assigned null.

- Constructor
  2.0.0.0
  4.0.0.0
  The initial value of the new instance.

  Constructs and initializes a new instance of giving it the specified initial value.

  Once this constructor has executed, applying to the new instance returns .

- Method
  2.0.0.0
  4.0.0.0
  System.Boolean ``

  If the property of the current structure is true, equality is determined by passing the parameter to the Equals method of the underlying value of the current structure.

  Indicates whether the current object is equal to a specified object.

  true if the parameter is equal to the current object; otherwise, false.

  This table describes how equality is defined for the compared values:

  Return Value

  Description

  true

  The property is false, and the parameter is null. That is, two null values are equal by definition.

  -or-

  The property is true, and the value returned by the property is equal to the parameter.

  false

  The property for the current structure is true, and the parameter is null.

  -or-

  The property for the current structure is false, and the parameter is not null.

  -or-

  The property for the current structure is true, and the value returned by the property is not equal to the parameter.

  An object.
- Method
  2.0.0.0
  4.0.0.0
  System.Int32

  The algorithm used to generate the hash code is unspecified.

  This method overrides .

  Retrieves the hash code of the object returned by the property.

  The hash code of the object returned by the property if the property is true, or zero if the property is false.

- Method
  2.0.0.0
  4.0.0.0
  T

  The method returns a value even if the property is false (unlike the property, which throws an exception).

  Retrieves the value of the current object, or the object's default value.

  The value of the property if the property is true; otherwise, the default value of the current object. The type of the default value is the type argument of the current object, and the value of the default value consists solely of binary zeroes.

- Method
  2.0.0.0
  4.0.0.0
  T `` To be added.

  Returns the value of the current instance, or if it has none, returns .

  A value of type , which is either the value of the current instance, or if it has none, the value of .

  allows the default value for type to be returned if the current instance contains no value.

- Property
  2.0.0.0
  4.0.0.0
  System.Boolean

  if the current instance contains a value; otherwise .

  If the property is true, the value of the current object can be accessed with the property. Otherwise, attempting to access its value throws an exception.

  Gets a value indicating whether the current object has a valid value of its underlying type.

- Method
  2.0.0.0
  4.0.0.0
  T `` The value to convert to type .

  Perform an explicit conversion of a value to type .

  The value, if any, of the specified nullable value. Otherwise, a is thrown.

  The conversion implemented by this method corresponds exactly to obtaining the value of the property.

  is .
- Method
  2.0.0.0
  4.0.0.0
  System.Nullable<T> `` The value to convert to .

  Perform an implicit conversion of a value to .

  A with the specified value.

  The conversion implemented by this method corresponds exactly to invoking the constructor.

- Method
  2.0.0.0
  4.0.0.0
  System.String

  The property returns the string yielded by calling the ToString property of the object returned by the property.

  Returns the text representation of the value of the current object.

  The text representation of the value of the current object if the property is true, or an empty string ("") if the property is false.

- Property
  2.0.0.0
  4.0.0.0
  T

  The value of the current instance.

  is .

  If a value of type T has not been assigned to the object, you can compare it to null and retrieve its property, but you cannot access its property or call its other members.

  Gets the value of the current object if it has been assigned a valid underlying value.