AllowNullDictionaryTKey, TValueTryAdd Method

Attempts to add the specified key and value to the AllowNullDictionaryTKey, TValue without overwriting an existing entry.

Definition

Namespace: KGySoft.Collections
Assembly: KGySoft.CoreLibraries (in KGySoft.CoreLibraries.dll) Version: 10.5.0
C#
public bool TryAdd(
	TKey key,
	TValue value
)

Parameters

key  TKey
The key of the element to add. In this dictionary it can be even .
value  TValue
The value of the element to add.

Return Value

Boolean
if the key and value pair was added to the AllowNullDictionaryTKey, TValue successfully; otherwise, .

Remarks

Unlike the Add method, this method doesn't throw an exception if the element with the given key exists in the AllowNullDictionaryTKey, TValue. Unlike the indexer, TryAdd doesn't override the element if the element with the given key exists in the dictionary. If the key already exists, TryAdd does nothing and returns .

See Also