Class DictionaryExtensions
Extension methods for the System.Collections.Generic.Dictionary<TKey, TValue>.
Inheritance
Namespace: Cuemon.Collections.Generic
Assembly: Cuemon.Core.dll
Syntax
public static class DictionaryExtensions
Methods
| Improve this DocGetValueOrDefault<TKey, TValue>(IDictionary<TKey, TValue>, TKey)
Gets the value associated with the specified key
or default(
when the key does not exists in the TValue
)dictionary
.
Declaration
public static TValue GetValueOrDefault<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, TKey key)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IDictionary<TKey, TValue> | dictionary | The dictionary to extend. |
TKey | key | The key of the value to get. |
Returns
Type | Description |
---|---|
TValue | Either the value associated with the specified |
Type Parameters
Name | Description |
---|---|
TKey | The type of the keys in the |
TValue | The type of the values in the |
GetValueOrDefault<TKey, TValue>(IDictionary<TKey, TValue>, TKey, Func<TValue>)
Gets the value associated with the specified key
or a default value through defaultProvider
when the key does not exists in the dictionary
.
Declaration
public static TValue GetValueOrDefault<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, TKey key, Func<TValue> defaultProvider)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IDictionary<TKey, TValue> | dictionary | The dictionary to extend. |
TKey | key | The key of the value to get. |
System.Func<TValue> | defaultProvider | The function delegate that will provide a default value when the |
Returns
Type | Description |
---|---|
TValue | Either the value associated with the specified |
Type Parameters
Name | Description |
---|---|
TKey | The type of the keys in the |
TValue | The type of the values in the |
TryGetValue<TKey, TValue>(IDictionary<TKey, TValue>, TKey, Func<IEnumerable<TKey>, TKey>, out TValue)
Gets the value
associated with the specified key
.
Declaration
public static bool TryGetValue<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, TKey key, Func<IEnumerable<TKey>, TKey> keySelector, out TValue value)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IDictionary<TKey, TValue> | dictionary | The dictionary to extend. |
TKey | key | The key of the value to get. |
System.Func<System.Collections.Generic.IEnumerable<TKey>, TKey> | keySelector | The function delegate that will resolve an alternate key from the specified |
TValue | value | When this method returns, contains the value associated with the specified |
Returns
Type | Description |
---|---|
System.Boolean |
|
Type Parameters
Name | Description |
---|---|
TKey | The type of the keys in the |
TValue | The type of the values in the |