mscorlib(4.0.0.0) API with additions
System.Nullable< T > Class Template Reference

Represents a value type that can be assigned null. More...

Public Member Functions

 Nullable (T value)
 Initializes a new instance of the T:System.Nullable`1 structure to the specified value. More...
 
T GetValueOrDefault ()
 Retrieves the value of the current T:System.Nullable`1 object, or the object's default value. More...
 
T GetValueOrDefault (T defaultValue)
 Retrieves the value of the current T:System.Nullable`1 object, or the specified default value. More...
 
override bool Equals (object other)
 Indicates whether the current T:System.Nullable`1 object is equal to a specified object. More...
 
override int GetHashCode ()
 Retrieves the hash code of the object returned by the P:System.Nullable`1.Value property. More...
 
override string ToString ()
 Returns the text representation of the value of the current T:System.Nullable`1 object. More...
 

Static Public Member Functions

static implicit operator T? (T value)
 Creates a new T:System.Nullable`1 object initialized to a specified value. More...
 
static operator T (T? value)
 Defines an explicit conversion of a T:System.Nullable`1 instance to its underlying value. More...
 
static int Compare< T > (T? n1, T? n2)
 Compares the relative values of two T:System.Nullable`1 objects. More...
 
static bool Equals< T > (T? n1, T? n2)
 Indicates whether two specified T:System.Nullable`1 objects are equal. More...
 
static Type GetUnderlyingType (Type nullableType)
 Returns the underlying type argument of the specified nullable type. More...
 

Public Attributes

internal T value
 

Properties

bool HasValue [get]
 Gets a value indicating whether the current T:System.Nullable`1 object has a valid value of its underlying type. More...
 
T Value [get]
 Gets the value of the current T:System.Nullable`1 object if it has been assigned a valid underlying value. More...
 

Detailed Description

Represents a value type that can be assigned null.

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

Template Parameters
TThe underlying value type of the T:System.Nullable`1 generic type.
Type Constraints
T :struct 

Definition at line 12 of file Nullable.cs.

Constructor & Destructor Documentation

◆ Nullable()

System.Nullable< T >.Nullable ( T  value)

Initializes a new instance of the T:System.Nullable`1 structure to the specified value.

Parameters
valueA value type.

Definition at line 53 of file Nullable.cs.

Member Function Documentation

◆ Compare< T >()

static int System.Nullable< T >.Compare< T > ( T n1,
T n2 
)
static

Compares the relative values of two T:System.Nullable`1 objects.

Parameters
n1A T:System.Nullable`1 object.
n2A T:System.Nullable`1 object.
Template Parameters
TThe underlying value type of the n1 and n2 parameters.
Returns
An integer that indicates the relative values of the n1 and n2 parameters.Return ValueDescriptionLess than zeroThe P:System.Nullable`1.HasValue property for n1 is false, and the P:System.Nullable`1.HasValue property for n2 is true.-or-The P:System.Nullable`1.HasValue properties for n1 and n2 are true, and the value of the P:System.Nullable`1.Value property for n1 is less than the value of the P:System.Nullable`1.Value property for n2 .ZeroThe P:System.Nullable`1.HasValue properties for n1 and n2 are false.-or-The P:System.Nullable`1.HasValue properties for n1 and n2 are true, and the value of the P:System.Nullable`1.Value property for n1 is equal to the value of the P:System.Nullable`1.Value property for n2 .Greater than zeroThe P:System.Nullable`1.HasValue property for n1 is true, and the P:System.Nullable`1.HasValue property for n2 is false.-or-The P:System.Nullable`1.HasValue properties for n1 and n2 are true, and the value of the P:System.Nullable`1.Value property for n1 is greater than the value of the P:System.Nullable`1.Value property for n2 .
Type Constraints
T :struct 

Definition at line 160 of file Nullable.cs.

◆ Equals()

override bool System.Nullable< T >.Equals ( object  other)

Indicates whether the current T:System.Nullable`1 object is equal to a specified object.

Parameters
otherAn object.
Returns
true if the other parameter is equal to the current T:System.Nullable`1 object; otherwise, false. This table describes how equality is defined for the compared values: Return ValueDescription true The P:System.Nullable`1.HasValue property is false, and the other parameter is null. That is, two null values are equal by definition.-or-The P:System.Nullable`1.HasValue property is true, and the value returned by the P:System.Nullable`1.Value property is equal to the other parameter. false The P:System.Nullable`1.HasValue property for the current T:System.Nullable`1 structure is true, and the other parameter is null.-or-The P:System.Nullable`1.HasValue property for the current T:System.Nullable`1 structure is false, and the other parameter is not null.-or-The P:System.Nullable`1.HasValue property for the current T:System.Nullable`1 structure is true, and the value returned by the P:System.Nullable`1.Value property is not equal to the other parameter.

Definition at line 91 of file Nullable.cs.

◆ Equals< T >()

static bool System.Nullable< T >.Equals< T > ( T n1,
T n2 
)
static

Indicates whether two specified T:System.Nullable`1 objects are equal.

Parameters
n1A T:System.Nullable`1 object.
n2A T:System.Nullable`1 object.
Template Parameters
TThe underlying value type of the n1 and n2 parameters.
Returns
true if the n1 parameter is equal to the n2 parameter; otherwise, false. The return value depends on the P:System.Nullable`1.HasValue and P:System.Nullable`1.Value properties of the two parameters that are compared.Return ValueDescription true The P:System.Nullable`1.HasValue properties for n1 and n2 are false. -or-The P:System.Nullable`1.HasValue properties for n1 and n2 are true, and the P:System.Nullable`1.Value properties of the parameters are equal. false The P:System.Nullable`1.HasValue property is true for one parameter and false for the other parameter.-or-The P:System.Nullable`1.HasValue properties for n1 and n2 are true, and the P:System.Nullable`1.Value properties of the parameters are unequal.
Type Constraints
T :struct 

Definition at line 189 of file Nullable.cs.

◆ GetHashCode()

override int System.Nullable< T >.GetHashCode ( )

Retrieves the hash code of the object returned by the P:System.Nullable`1.Value property.

Returns
The hash code of the object returned by the P:System.Nullable`1.Value property if the P:System.Nullable`1.HasValue property is true, or zero if the P:System.Nullable`1.HasValue property is false.

Definition at line 107 of file Nullable.cs.

◆ GetUnderlyingType()

static Type System.Nullable< T >.GetUnderlyingType ( Type  nullableType)
static

Returns the underlying type argument of the specified nullable type.

Parameters
nullableTypeA T:System.Type object that describes a closed generic nullable type.
Returns
The type argument of the nullableType parameter, if the nullableType parameter is a closed generic nullable type; otherwise, null.
Exceptions
T:System.ArgumentNullExceptionnullableType is null.

Definition at line 212 of file Nullable.cs.

◆ GetValueOrDefault() [1/2]

T System.Nullable< T >.GetValueOrDefault ( )

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

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

Definition at line 63 of file Nullable.cs.

◆ GetValueOrDefault() [2/2]

T System.Nullable< T >.GetValueOrDefault ( T  defaultValue)

Retrieves the value of the current T:System.Nullable`1 object, or the specified default value.

Parameters
defaultValueA value to return if the P:System.Nullable`1.HasValue property is false.
Returns
The value of the P:System.Nullable`1.Value property if the P:System.Nullable`1.HasValue property is true; otherwise, the defaultValue parameter.

Definition at line 73 of file Nullable.cs.

◆ operator T()

static System.Nullable< T >.operator T ( T value)
explicitstatic

Defines an explicit conversion of a T:System.Nullable`1 instance to its underlying value.

Parameters
valueA nullable value.
Returns
The value of the P:System.Nullable`1.Value property for the value parameter.

Definition at line 143 of file Nullable.cs.

◆ operator T?()

static implicit System.Nullable< T >.operator T? ( T  value)
static

Creates a new T:System.Nullable`1 object initialized to a specified value.

Parameters
valueA value type.
Returns
A T:System.Nullable`1 object whose P:System.Nullable`1.Value property is initialized with the value parameter.

Definition at line 133 of file Nullable.cs.

◆ ToString()

override string System.Nullable< T >.ToString ( )

Returns the text representation of the value of the current T:System.Nullable`1 object.

Returns
The text representation of the value of the current T:System.Nullable`1 object if the P:System.Nullable`1.HasValue property is true, or an empty string ("") if the P:System.Nullable`1.HasValue property is false.

Definition at line 119 of file Nullable.cs.

Property Documentation

◆ HasValue

bool System.Nullable< T >.HasValue
get

Gets a value indicating whether the current T:System.Nullable`1 object has a valid value of its underlying type.

Returns
true if the current T:System.Nullable`1 object has a value; false if the current T:System.Nullable`1 object has no value.

Definition at line 23 of file Nullable.cs.

◆ Value

T System.Nullable< T >.Value
get

Gets the value of the current T:System.Nullable`1 object if it has been assigned a valid underlying value.

Returns
The value of the current T:System.Nullable`1 object if the P:System.Nullable`1.HasValue property is true. An exception is thrown if the P:System.Nullable`1.HasValue property is false.
Exceptions
T:System.InvalidOperationExceptionThe P:System.Nullable`1.HasValue property is false.

Definition at line 37 of file Nullable.cs.


The documentation for this class was generated from the following file: