CollectionsMarshal.GetValueRefOrAddDefault<TKey,TValue> 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取对指定字典中 的 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>中删除。
适用于
反馈
https://aka.ms/ContentUserFeedback。
即将发布:在整个 2024 年,我们将逐步淘汰作为内容反馈机制的“GitHub 问题”,并将其取代为新的反馈系统。 有关详细信息,请参阅:提交和查看相关反馈