Rediger

Del via


Nullable.GetValueRefOrDefaultRef<T>(Nullable<T>) Method

Definition

Retrieves a readonly reference to the location in the Nullable<T> instance where the value is stored.

public:
generic <typename T>
 where T : value class static T& ^ GetValueRefOrDefaultRef(Nullable<T> % nullable);
public static ref readonly T GetValueRefOrDefaultRef<T> (in T? nullable) where T : struct;
public static ref readonly T GetValueRefOrDefaultRef<T> (ref T? nullable) where T : struct;
static member GetValueRefOrDefaultRef : Nullable -> 'T (requires 'T : struct)
Public Shared Function GetValueRefOrDefaultRef(Of T As Structure) (ByRef nullable As Nullable(Of T)) As T

Type Parameters

T

The underlying value type of the Nullable<T> generic type.

Parameters

nullable
Nullable<T>

The readonly reference to the input Nullable<T> value.

Returns

T

A readonly reference to the location where the instance's T value is stored. If the instance's HasValue is false, the current value at that location may be the default value.

Remarks

As the returned readonly reference refers to data that is stored in the input nullable value, this method should only ever be called when the input reference points to a value with an actual location and not an "rvalue" (an expression that may appear on the right side but not left side of an assignment). That is, if this API is called and the input reference points to a value that is produced by the compiler as a defensive copy or a temporary copy, the behavior might not match the desired one.

Applies to