StringKeyedDictionaryTValueTryAdd Method

Attempts to add the specified key and value to the StringKeyedDictionaryTValue without overwriting an existing entry.

Definition

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

Parameters

key  String
The key of the element to add.
value  TValue
The value of the element to add. The value can be for reference types.

Return Value

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

Remarks

Unlike the Add method, this method doesn't throw an exception if the element with the given key exists in the StringKeyedDictionaryTValue. 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 .

Exceptions

See Also