CollectionExtensions.TryAdd<TKey,TValue> Method
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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>
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.
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.
dictionary
is null
.
Product | Versions |
---|---|
.NET | Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10 |
.NET Standard | 2.1 |
.NET feedback
.NET is an open source project. Select a link to provide feedback: