Alexandre
Alexandre

Reputation: 13308

Convert IEnumerable<Dictionary<int, string>> to List<Dictionary<int, string>>

var a = GetIEnumerableDictionary();

a is IEnumerable<Dictionary<int, string>>. How do I convert a to List<Dictionary<int, string>> ?

Upvotes: 1

Views: 967

Answers (2)

Ray Booysen
Ray Booysen

Reputation: 30021

a.ToList() should do the trick.

The ToList() extension method lives in the System.Linq namespace. If Linq is not available, the List<T> constructor takes an IEnumerable<T> as a parameter, as Jalal has already answered on this page.

Upvotes: 9

Jalal Said
Jalal Said

Reputation: 16162

You can use the List IEnumerable<T> constructor, so:

List<Dictionary<int, string>> myList = new List<Dictionary<int, string>>(a);

Upvotes: 5

Related Questions