我有一个LINQ查询返回IEnumerable<List<int>>
但我只想返回List<int>
所以我想将我的所有记录合并到我IEnumerable<List<int>>
只有一个数组.
示例:
IEnumerable<List<int>> iList = from number in
(from no in Method() select no) select number;
Run Code Online (Sandbox Code Playgroud)
我想把我的所有结果IEnumerable<List<int>>
都只拿到一个List<int>
因此,从源数组:[1,2,3,4]和[5,6,7]
我只想要一个阵列[1,2,3,4,5,6,7]
谢谢
Mik*_*Two 527
尝试 SelectMany()
var result = iList.SelectMany( i => i );
Run Code Online (Sandbox Code Playgroud)
rec*_*ive 81
使用查询语法:
var values =
from inner in outer
from value in inner
select value;
Run Code Online (Sandbox Code Playgroud)
Dyl*_*tie 22
iList.SelectMany(x => x).ToArray()
Run Code Online (Sandbox Code Playgroud)
Dan*_*iel 10
如果你有一个List<List<int>> k
你可以做到的
List<int> flatList= k.SelectMany( v => v).ToList();
Run Code Online (Sandbox Code Playgroud)