将IEnumerable <Dictionary <int,string >>转换为List <Dictionary <int,string >>

Ale*_*dre 1 c# ienumerable list

var a = GetIEnumerableDictionary();
Run Code Online (Sandbox Code Playgroud)

a是IEnumerable<Dictionary<int, string>>.我如何将a转换为List<Dictionary<int, string>>?

Ray*_*sen 9

a.ToList() 应该做的伎俩.

该ToList()扩展方法住在System.Linq命名空间.如果Linq不可用,则List<T>构造函数将IEnumerable<T>参数作为参数,因为Jalal已在此页面上回答.


Jal*_*aid 5

您可以使用List IEnumerable<T>构造函数,因此:

List<Dictionary<int, string>> myList = new List<Dictionary<int, string>>(a);
Run Code Online (Sandbox Code Playgroud)