CollectionExtensions.TryAdd<TKey,TValue>(IDictionary<TKey,TValue>, TKey, TValue) Método

Definición

Intenta agregar los elementos key y value especificados a 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

Parámetros de tipo

TKey

Tipo de las claves del diccionario.The type of the keys in the dictionary.

TValue

Tipo de los valores del diccionario.The type of the values in the dictionary.

Parámetros

dictionary
IDictionary<TKey,TValue>

Diccionario con claves de tipo TKey y valores de tipo TValue.A dictionary with keys of type TKey and values of type TValue.

key
TKey

Clave del valor que se va a agregar.The key of the value to add.

value
TValue

El valor que se va a agregar.The value to add.

Devoluciones

true cuando key y value se agregan correctamente a dictionary; false cuando dictionary ya contiene el elemento key especificado, en cuyo caso no se agrega nada.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.

Excepciones

dictionary es null.dictionary is null.

Se aplica a