Table of Contents

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

dictionary Dictionary<TKey, TValue>

The dictionary to update.

key TKey

The key of the value to add or update.

value TValue

The value to add or update.

Type Parameters

TKey

The type of key item within the dictionary.

TValue

The type of value item within the dictionary.

Exceptions

ArgumentNullException

The dictionary or key is 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

dictionary Dictionary<TKey, TValue>

The dictionary to get a value from.

key TKey

The key to get a value for.

defaultValue TValue

The default value to return if not exists. Default, null.

Returns

TValue

The value if it exists for the key; otherwise, null.

Type Parameters

TKey

The type of key item within the dictionary.

TValue

The type of value item within the dictionary.