CollectionExtensions.TryAdd<TKey,TValue> 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
尝试添加指定key和value添加到 。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当已包含指定dictionary时key,在这种情况下,不会添加任何内容。
例外
dictionary 是 null。