共用方式為


CollectionsMarshal.GetValueRefOrNullRef<TKey,TValue> 方法

定義

取得 中 的參考TValue,如果 不存在於 中,null則取得 參考dictionaryDictionary<TKey,TValue>

public:
generic <typename TKey, typename TValue>
 static TValue % GetValueRefOrNullRef(System::Collections::Generic::Dictionary<TKey, TValue> ^ dictionary, TKey key);
public static ref TValue GetValueRefOrNullRef<TKey,TValue> (System.Collections.Generic.Dictionary<TKey,TValue> dictionary, TKey key);
static member GetValueRefOrNullRef : System.Collections.Generic.Dictionary<'Key, 'Value> * 'Key -> 'Value
Public Shared Function GetValueRefOrNullRef(Of TKey, TValue) (dictionary As Dictionary(Of TKey, TValue), key As TKey) As TValue

類型參數

TKey

索引鍵的類型。

TValue

值的型別。

參數

dictionary
Dictionary<TKey,TValue>

要從中取得 ref 的 TValue 字典。

key
TKey

用於查閱的索引鍵。

傳回

TValue

中 的參考TValue,如果 不存在於 中dictionary,則為 參考nullDictionary<TKey,TValue>

備註

當 ref TValue 正在使用時,不應從 新增或移除Dictionary<TKey,TValue>專案。

您可以呼叫 System.Runtime.CompilerServices.Unsafe.IsNullRef<T>(T)來偵測 refnull

適用於