ConcurrentDictionary<TKey, TValue>::TryAdd Method (TKey, TValue)
Attempts to add the specified key and value to the System.Collections.Concurrent::ConcurrentDictionary<TKey, TValue>.
Assembly: mscorlib (in mscorlib.dll)
Parameters
- key
-
Type:
TKey
The key of the element to add.
- value
-
Type:
TValue
The value of the element to add. The value can be null for reference types.
Return Value
Type: System::Booleantrue if the key/value pair was added to the System.Collections.Concurrent::ConcurrentDictionary<TKey, TValue> successfully; false if the key already exists.
| Exception | Condition |
|---|---|
| ArgumentNullException | key is null. |
| OverflowException | The dictionary already contains the maximum number of elements (MaxValue). |
This method returns false if the key already exists. Use the TryUpdate or AddOrUpdate method to update the value in case a key already exists.
Available since 8
.NET Framework
Available since 4.0
Portable Class Library
Supported in: portable .NET platforms
Windows Phone
Available since 8.1