Stravaig.Extensions.Core

A set of small extensions to make life a little easier.

View on GitHub View on NuGet
Documentation last built on Thursday, 16 November, 2023

IEnumerable< KeyValuePair<TKey, TValue> >.ToDictionary(…)

Converts the KeyValuePair<TKey,TValue> to a Dictionary<TKey,TValue>


Dictionary<TKey,TValue> ToDictionary(this IEnumerable< KeyValuePair<TKey,TValue> > source)

Parameters

Example

KeyValuePair<string, object>[] kvp = 
    {
        new("a", 1),
        new("b", true),
        new("c", 123.45M)
    };

Dictionary<string, object> dictionary = kvp.ToDictionary();

Dictionary<TKey,TValue> ToDictionary(this IEnumerable< KeyValuePair<TKey,TValue> > source, IEqualityComparer comparer)

Parameters

Example

KeyValuePair<string, object>[] kvp = 
    {
        new("a", 1),
        new("b", true),
        new("c", 123.45M)
    };

Dictionary<string, object> dictionary = kvp.ToDictionary(StringComparer.OrdinalIgnoreCase);

var a = dictionary["A"]; // a is populated with 1