Mono Class Library: System Namespace

System.Nullable<T> Structure

Represents a nullable value type. An instance of Nullable<T>can contain a value of type T or an indication that the instance contains no value. Upon boxing, if it contains no value, it will be converted to the null reference; otherwise, it will be converted to a boxed T. [Note: Because of the constraint on the generic parameter, T cannot be of type Nullable<U> for any U. end note] [Edit]

See Also: Nullable<T> Members

public struct Nullable<T>
where T : struct

Type Parameters

T
Documentation for this section has not yet been entered. [Edit]

Remarks

The Nullable<T> value type represents a value of a given type T or an indication that the instance contains no value. Such a nullable type is useful in a variety of situations, such as in denoting nullable columns in a database table or optional attributes in an XML element. The runtime transforms Nullable<T>instances without values into true nulls when performing a box operation; instances with values are transformed into boxed T's containing the Nullable<T>'s Value.

An instance of Nullable<T> has two properties, Nullable<T>.HasValue and Nullable<T>.Value. Nullable<T>.HasValue is used to determine whether the current instance currently has a value. It returns true or false, and never throws an exception. Nullable<T>.Value returns the current value of the instance, provided it has one (i.e., Nullable<T>.HasValue is true); otherwise, it throws an exception.

In addition to the above properties, there is a pair of methods, both overloads of Nullable<T>.GetValueOrDefault. The version taking no arguments returns the instance's current value, if it has one; otherwise, it returns the default value of type T. The version taking an argument of type T returns the instance's current value, if it has one; otherwise, it returns the default value argument passed to it.

Applying Nullable<T>.HasValue to an instance that has the default initial value, causes false to be returned.

[Edit]

Requirements

Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 2.0.0.0
Since: .NET 2.0