CollectionExtensions.TryAdd<TKey,TValue>(IDictionary<TKey,TValue>, TKey, TValue) Methode
Definition
Versucht, den angegebenen key
und den angegebenen value
dem dictionary
hinzuzufügen.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
Typparameter
- TKey
Der Typ der Schlüssel im Wörterbuch.The type of the keys in the dictionary.
- TValue
Der Typ der Werte im Wörterbuch.The type of the values in the dictionary.
Parameter
- dictionary
- IDictionary<TKey,TValue>
Ein Wörterbuch mit Schlüsseln vom Typ TKey
und Werten vom Typ TValue
.A dictionary with keys of type TKey
and values of type TValue
.
- key
- TKey
Der Schlüssel des hinzuzufügenden Werts.The key of the value to add.
- value
- TValue
Der hinzuzufügende Wert.The value to add.
Gibt zurück
true
, wenn der key
und der value
erfolgreich dem dictionary
hinzugefügt wurden. false
, wenn das dictionary
den angegebenen key
bereits enthält; in diesem Fall wird nichts hinzugefügt.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.
Ausnahmen
dictionary
ist null
.dictionary
is null
.