Method SafeAdd
SafeAdd<TKey, TValue>(Dictionary<TKey, TValue>, TKey, TValue, bool)
Safe version of Dictionary Add function, which will not trigger error while target key already exists
Declaration
public static bool SafeAdd<TKey, TValue>(this Dictionary<TKey, TValue> dictionary, TKey key, TValue value, bool @override = false)
Parameters
Type | Name | Description |
---|---|---|
Dictionary<TKey, TValue> | dictionary | The dictionary to add a value to. |
TKey | key | The key to add. |
TValue | value | The value to add. |
bool | override | Whether to override the existing value if the key is already present in the dictionary. |
Returns
Type | Description |
---|---|
bool | True if the key was already present in the dictionary, false if the key was added successfully. |
Type Parameters
Name | Description |
---|---|
TKey | The type of the dictionary keys. |
TValue | The type of the dictionary values. |