Nullable.GetValueRefOrDefaultRef<T>(Nullable<T>) 方法

定義

擷取儲存值之實例中 Nullable<T> 位置的唯讀參考。

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

類型參數

T

Nullable<T> 泛型型別的基礎實值型別。

參數

nullable
Nullable<T>

輸入 Nullable<T> 值的唯讀參考。

傳回

T

實例值儲存位置的 T 唯讀參考。 如果 實例為 HasValuefalse ,則該位置的目前值可能是預設值。

備註

當傳回的唯讀參考參考儲存在輸入 nullable 值中的資料時,只有在輸入參考指向具有實際位置的值,而不是 「rvalue」 (可能出現在右側但不是指派左側的運算式時,才應該呼叫此方法) 。 也就是說,如果呼叫此 API,且輸入參考指向編譯器所產生的值作為防禦性複本或暫時複本,則行為可能不符合所需的值。

適用於