CollectionExtensions.TryAdd<TKey,TValue>(IDictionary<TKey,TValue>, TKey, TValue) メソッド

定義

指定した keyvaluedictionary に追加しようとします。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

型パラメーター

TKey

ディクショナリ内のキーの型。The type of the keys in the dictionary.

TValue

ディクショナリ内の値の型。The type of the values in the dictionary.

パラメーター

dictionary
IDictionary<TKey,TValue>

TKey 型のキーと TValue 型の値を含むディクショナリ。A dictionary with keys of type TKey and values of type TValue.

key
TKey

追加する値のキー。The key of the value to add.

value
TValue

加算する値。The value to add.

戻り値

keyvaluedictionary に正常に追加された場合は、truedictionary に指定した key が既に含まれている場合は false (この場合、何も追加されません)。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.

例外

dictionarynullです。dictionary is null.

適用対象