我希望能够将IEnumerable<IEnumerable<T>>融合到IEnumerable<T>中(即将所有单独的集合合并为一个集合)。Union运算符仅适用于两个集合。有什么想法吗?
发布于 2008-11-26 16:05:46
试一试
var it = GetTheNestedCase();
return it.SelectMany(x => x);SelectMany是一个LINQ转换,它本质上是说“对于集合中的每一项,返回集合的元素”。它将把一个元素变成多个元素(因此是SelectMany)。它非常适合于将集合分解成一个平面列表。
发布于 2009-04-21 21:33:00
var lists = GetTheNestedCase();
return
from list in lists
from element in list
select element;是使用C# 3.0查询表达式语法完成此操作的另一种方式。
https://stackoverflow.com/questions/321229
复制相似问题