TryAdd Method
From Task Parallel System.Threading
|
|
| .NET Framework Class Library |
| ConcurrentDictionary<(Of <(TKey, TValue>)>)..::.TryAdd Method |
| ConcurrentDictionary<(Of <(TKey, TValue>)>) Class See Also Send Feedback |
Attempts to add the specified key and value to the ConcurrentDictionary<(Of <(TKey, TValue>)>).
Namespace:
System.Collections.Concurrent
Assembly:
System.Threading (in System.Threading.dll)
Syntax
| Visual Basic (Declaration) |
|---|
Public Function TryAdd ( _ key As TKey, _ value As TValue _ ) As Boolean |
| C# |
|---|
public bool TryAdd( TKey key, TValue value ) |
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 a null reference (Nothing in Visual Basic) for reference types.
Return Value
true if the key/value pair was added to the ConcurrentDictionary<(Of <(TKey, TValue>)>) successfully; otherwise, false.
Exceptions
| Exception | Condition |
|---|---|
| System..::.ArgumentNullException | key is null reference (Nothing in Visual Basic). |
| System..::.OverflowException | The ConcurrentDictionary<(Of <(TKey, TValue>)>) contains too many elements. |