你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

DictionaryExtensions.GetOrAddNonNull<TKey,TValue> 方法

定义

获取或添加与指定键关联的值。

public static TValue GetOrAddNonNull<TKey,TValue>(this System.Collections.Concurrent.ConcurrentDictionary<TKey,TValue> dictionary, TKey key, Func<TKey,TValue> valueFactory) where TValue : class;
static member GetOrAddNonNull : System.Collections.Concurrent.ConcurrentDictionary<'Key, 'Value (requires 'Value : null)> * 'Key * Func<'Key, 'Value (requires 'Value : null)> -> 'Value (requires 'Value : null)
<Extension()>
Public Function GetOrAddNonNull(Of TKey, TValue) (dictionary As ConcurrentDictionary(Of TKey, TValue), key As TKey, valueFactory As Func(Of TKey, TValue)) As TValue

类型参数

TKey

键参数的类型。

TValue

值参数的类型。

参数

dictionary
ConcurrentDictionary<TKey,TValue>

包含指定键的字典。

key
TKey

要获取其值的键。

valueFactory
Func<TKey,TValue>

值提供程序函数。

返回

TValue

如果找到指定键,则为与指定键关联的值;否则为值参数类型的默认值。

适用于