让我们假设我的列表是这样的:
List<List<string>> zz = new List<List<string>>() { new List<string>{"1","2","3"}, new List<string> { "4", "5", "6" } };
我想要一个列表作为输出,如下所示:
List<string> finalList = new List<string>{"1","2","3","4", "5", "6"};
如何展平?
答案 0 :(得分:9)
您可以使用SelectMany
var finalList = zz.SelectMany(x=>x).ToList();
答案 1 :(得分:2)
var finalList = zz.SelectMany(a => a).ToList();