Share via


ImmutableInterlocked.TryAdd<TKey,TValue> 方法

定义

将指定的键和值添加到字典(如果该键不在字典中)。

public:
generic <typename TKey, typename TValue>
 static bool TryAdd(System::Collections::Immutable::ImmutableDictionary<TKey, TValue> ^ % location, TKey key, TValue value);
public static bool TryAdd<TKey,TValue> (ref System.Collections.Immutable.ImmutableDictionary<TKey,TValue> location, TKey key, TValue value);
static member TryAdd : ImmutableDictionary * 'Key * 'Value -> bool
Public Shared Function TryAdd(Of TKey, TValue) (ByRef location As ImmutableDictionary(Of TKey, TValue), key As TKey, value As TValue) As Boolean

类型参数

TKey

集合中包含的键的类型。

TValue

集合中包含的值的类型。

参数

location
ImmutableDictionary<TKey,TValue>

要使用指定的键和值更新的字典。

key
TKey

要添加的键(如果字典中尚未定义该键)。

value
TValue

要相加的值。

返回

如果该键不在字典中,则为 true;否则为 false

适用于