CollectionsMarshal.GetValueRefOrAddDefault<TKey,TValue> 方法

定义

获取对指定字典中 的 TValue 引用,如果键不存在,则添加具有默认值的新条目。

public:
generic <typename TKey, typename TValue>
 static TValue % GetValueRefOrAddDefault(System::Collections::Generic::Dictionary<TKey, TValue> ^ dictionary, TKey key, [Runtime::InteropServices::Out] bool % exists);
public static ref TValue? GetValueRefOrAddDefault<TKey,TValue> (System.Collections.Generic.Dictionary<TKey,TValue> dictionary, TKey key, out bool exists);
static member GetValueRefOrAddDefault : System.Collections.Generic.Dictionary<'Key, 'Value> * 'Key * bool -> 'Value
Public Shared Function GetValueRefOrAddDefault(Of TKey, TValue) (dictionary As Dictionary(Of TKey, TValue), key As TKey, ByRef exists As Boolean) As TValue

类型参数

TKey

密钥的类型。

TValue

值的类型。

参数

dictionary
Dictionary<TKey,TValue>

要从中获取对 的引用 TValue 的字典。

key
TKey

用于查找的键。

exists
Boolean

此方法返回时,如果key字典中已存在,则包含 true ,以及false是否添加了新条目。

返回

TValue

TValue 指定字典中的 的引用。

注解

在使用 ref TValue 时,不应将项添加到 或从Dictionary<TKey,TValue>中删除。

适用于