GetOrAdd Method (TKey, TValue)

Task Parallel System.Threading

Adds a key/value pair to the ConcurrentDictionary<(Of <(TKey, TValue>)>) if the key does not already exist.

Namespace:  System.Collections.Concurrent
Assembly:  System.Threading (in System.Threading.dll)

Syntax

Visual Basic (Declaration)
Public Function GetOrAdd ( _
	key As TKey, _
	value As TValue _
) As TValue
C#
public TValue GetOrAdd(
	TKey key,
	TValue value
)

Parameters

key
Type: TKey
The key of the element to add.
value
Type: TValue
the value to be added, if the key does not already exist

Return Value

The value for the key. This will be either the existing value for the key if the key is already in the dictionary, or the new value if the key was not in the dictionary.

Exceptions

ExceptionCondition
System..::.ArgumentNullExceptionkey is a null reference (Nothing in Visual Basic).
System..::.OverflowExceptionThe dictionary contains too many elements.

See Also