How to convert IEnumerable of KeyValuePair<x, y> to Dictionary?
问题 Is there streamlined way to convert list/enumberable of KeyValuePair<T, U> to Dictionary<T, U> ? Linq transformation, .ToDictionary() extension did not work. 回答1: .ToDictionary(kvp=>kvp.Key,kvp=>kvp.Value); Isn't that much more work. 回答2: You can create your own extension method that would perform as you expect. public static class KeyValuePairEnumerableExtensions { public static Dictionary<TKey, TValue> ToDictionary<TKey, TValue>(this IEnumerable<KeyValuePair<TKey, TValue>> source) { return