CollectionExtensions.TryAdd<TKey,TValue>(IDictionary<TKey,TValue>, TKey, TValue) Metoda

Definicja

Próbuje dodać określony key i value do dictionary .Tries to add the specified key and value to the 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

Parametry typu

TKey

Typ kluczy w słowniku.The type of the keys in the dictionary.

TValue

Typ wartości w słowniku.The type of the values in the dictionary.

Parametry

dictionary
IDictionary<TKey,TValue>

Słownik z kluczami typu TKey i wartości typu TValue .A dictionary with keys of type TKey and values of type TValue.

key
TKey

Klucz wartości do dodania.The key of the value to add.

value
TValue

Wartość do dodania.The value to add.

Zwraca

Boolean

true gdy key i value zostały pomyślnie dodane do elementu dictionary ; false , gdy dictionary zawiera już określony key , w takim przypadku nic nie zostanie dodane.true when the key and value are successfully added to the dictionary; false when the dictionary already contains the specified key, in which case nothing gets added.

Wyjątki

dictionary to null.dictionary is null.

Dotyczy