public static IIndexed <TKey, TValue> ToIndexed <T, TKey, TValue, TComparer>( this IEnumerable <T> enumerable, Func <T, TKey> keySelector, Func <T, TValue> valueSelector, TComparer comparer ) where TComparer : IEqualityComparer <TKey> { var dictionary = new DictionarySlim <TKey, TValue, TComparer>(comparer); foreach (var item in enumerable) { dictionary.AddOrReplace(keySelector(item), valueSelector(item)); } return(dictionary); }