Mono Class Library: System NamespaceSystem.Nullable<T> Structure |
See Also: Nullable<T> Members
|
- T
- Documentation for this section has not yet been entered. [Edit]
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]
Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 2.0.0.0
Since: .NET 2.0