ToDictionary Method
Definition
- Namespace
- Cuemon.Extensions.Collections.Generic
- Assemblies
- Cuemon.Extensions.Collections.Generic.dll
ToDictionary<TKey, TValue>(IEnumerable<KeyValuePair<TKey, TValue>>)
Creates a Dictionary<TKey, TValue> from the specified source sequence.
public static IDictionary<TKey, TValue> ToDictionary<TKey, TValue>(this IEnumerable<KeyValuePair<TKey, TValue>> source)
Parameters
sourceIEnumerable<KeyValuePair<TKey, TValue>>An IEnumerable<T> to extend.
Returns
- IDictionary<TKey, TValue>
A Dictionary<TKey, TValue> that is equivalent to the specified
sourcesequence.
Type Parameters
TKeyThe type of keys in the
source.TValueThe type of values in the
source.
Exceptions
- ArgumentNullException
sourceis null.- ArgumentException
sourcecontains at least one KeyValuePair<TKey, TValue> that produces duplicate keys for two elements.
ToDictionary<TKey, TValue>(IEnumerable<KeyValuePair<TKey, TValue>>, IEqualityComparer<TKey>)
Creates a Dictionary<TKey, TValue> from the specified source sequence.
public static IDictionary<TKey, TValue> ToDictionary<TKey, TValue>(this IEnumerable<KeyValuePair<TKey, TValue>> source, IEqualityComparer<TKey> comparer)
Parameters
sourceIEnumerable<KeyValuePair<TKey, TValue>>An IEnumerable<T> to extend.
comparerIEqualityComparer<TKey>The IEqualityComparer<T> implementation to use when comparing keys.
Returns
- IDictionary<TKey, TValue>
A Dictionary<TKey, TValue> that is equivalent to the specified
sourcesequence.
Type Parameters
TKeyThe type of keys in the
source.TValueThe type of values in the
source.
Exceptions
- ArgumentNullException
sourceis null - or -compareris null.- ArgumentException
sourcecontains at least one KeyValuePair<TKey, TValue> that produces duplicate keys for two elements.