Table of Contents

TryAdd Method

Definition

Namespace
Cuemon.Extensions.Collections.Generic
Assemblies
Cuemon.Extensions.Collections.Generic.dll
Source
src/Cuemon.Extensions.Collections.Generic/DictionaryExtensions.cs

TryAdd<TKey, TValue>(IDictionary<TKey, TValue>, TKey, TValue, Func<IDictionary<TKey, TValue>, bool>)

Attempts to add the specified key and value to the dictionary.

public static bool TryAdd<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, TKey key, TValue value, Func<IDictionary<TKey, TValue>, bool> condition)

Parameters

dictionary IDictionary<TKey, TValue>

The IDictionary<TKey, TValue> to extend.

key TKey

The key of the element to add.

value TValue

The value of the element to add.

condition Func<IDictionary<TKey, TValue>, bool>

The function delegate that specifies the condition for adding the element.

Returns

bool

true if the key/value pair was added to the dictionary successfully; otherwise, false.

Type Parameters

TKey
TValue

Exceptions

ArgumentNullException

dictionary cannot be null -or- key cannot be null -or- condition cannot be null.