CollectionExtensions.TryAdd<TKey,TValue> Metod

Definition

Försöker lägga till den angivna key och value till 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

Typparametrar

TKey

Typ av nycklar i ordlistan.

TValue

Typ av värden i ordlistan.

Parametrar

dictionary
IDictionary<TKey,TValue>

En ordlista med nycklar av typen TKey och värden av typen TValue.

key
TKey

Nyckeln för det värde som ska läggas till.

value
TValue

Värdet som ska läggas till.

Returer

true key när och value har lagts till i dictionary; false när den dictionary redan innehåller den angivna key, i vilket fall ingenting läggs till.

Undantag

dictionary är null.

Gäller för