Convert List of KeyValuePair into IDictionary "C#"

Viewed 27696

My scenario,

how to convert List<KeyValuePair<string, string>> into IDictionary<string, string>?

4 Answers

You can also use the constructor overload of Dictionary<TKey,TValue> that takes an IEnumerable<KeyValuePair<TKey,TValue>> as parameter.

var list = new List<KeyValuePair<int, string>>();
var dictionary = new Dictionary<int, string>(list);
Related