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。