Class DictionaryExtensions
- Namespace
- MADE.Collections
- Assembly
- MADE.Collections.dll
Defines a collection of extensions for dictionaries.
public static class DictionaryExtensions
- Inheritance
-
DictionaryExtensions
- Inherited Members
Methods
AddOrUpdate<TKey, TValue>(Dictionary<TKey, TValue>, TKey, TValue)
Adds or updates a value within a dictionary.
public static void AddOrUpdate<TKey, TValue>(this Dictionary<TKey, TValue> dictionary, TKey key, TValue value) where TKey : notnull
Parameters
dictionaryDictionary<TKey, TValue>The dictionary to update.
keyTKeyThe key of the value to add or update.
valueTValueThe value to add or update.
Type Parameters
TKeyThe type of key item within the dictionary.
TValueThe type of value item within the dictionary.
Exceptions
- ArgumentNullException
The
dictionaryorkeyis null.
GetValueOrDefault<TKey, TValue>(Dictionary<TKey, TValue>, TKey, TValue?)
Gets a value from a dictionary by the specified key, or returns a default value.
public static TValue? GetValueOrDefault<TKey, TValue>(this Dictionary<TKey, TValue> dictionary, TKey key, TValue? defaultValue = default) where TKey : notnull
Parameters
dictionaryDictionary<TKey, TValue>The dictionary to get a value from.
keyTKeyThe key to get a value for.
defaultValueTValueThe default value to return if not exists. Default, null.
Returns
- TValue
The value if it exists for the key; otherwise, null.
Type Parameters
TKeyThe type of key item within the dictionary.
TValueThe type of value item within the dictionary.