CollectionExtensions.TryAdd<TKey,TValue> 方法

定义

尝试添加指定keyvalue添加到 。dictionary

public:
generic <typename TKey, typename TValue>
[System::Runtime::CompilerServices::Extension]
 static bool TryAdd(System::Collections::Generic::IDictionary<TKey, TValue> ^ dictionary, TKey key, TValue value);
public static bool TryAdd<TKey,TValue>(this System.Collections.Generic.IDictionary<TKey,TValue> dictionary, TKey key, TValue value);
static member TryAdd : System.Collections.Generic.IDictionary<'Key, 'Value> * 'Key * 'Value -> bool
<Extension()>
Public Function TryAdd(Of TKey, TValue) (dictionary As IDictionary(Of TKey, TValue), key As TKey, value As TValue) As Boolean

类型参数

TKey

字典中键的类型。

TValue

字典中值的类型。

参数

dictionary
IDictionary<TKey,TValue>

包含类型 TKey 键和类型的 TValue值的字典。

key
TKey

要添加的值的键。

value
TValue

要添加的值。

返回

true key当成功value添加到 dictionary;false当已包含指定dictionarykey,在这种情况下,不会添加任何内容。

例外

dictionarynull

适用于