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

要加入的值。

傳回

keyvalue 成功新增至 dictionary 時,為 true;當 dictionary 已包含指定的 key 時 (在此狀況下不新增任何項目),則為 false

例外狀況

dictionarynull

適用於