System.Nullable<T>.GetValueOrDefault Method

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

Syntax

public T GetValueOrDefault ()

Returns

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

Remarks

The erload:System.Nullable`1.GetValueOrDefault method returns a value even if the Nullable`1.HasValue property is false (unlike the Nullable`1.Value property, which throws an exception).

Requirements

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