开发者

Concatenate lists with LINQ

开发者 https://www.devze.com 2023-02-05 05:55 出处:网络
Is it possibl开发者_如何转开发e to concatenate a List<List<T>> into a List<T> with a single operation in a way which isn\'t horrible slow, i.e:

Is it possibl开发者_如何转开发e to concatenate a List<List<T>> into a List<T> with a single operation in a way which isn't horrible slow, i.e:

List<List<int>> listOfLists = new List<List<int>>();
List<int> concatenatedList = listOfLists.Something...

?


listOfLists.SelectMany( l => l );

full line:

List<int> concatenatedList = listOfLists.SelectMany( l => l ).ToList();


Something like this:

listOfLists.Aggregate(new int[0], (res, list) => res.Concat(list));
0

精彩评论

暂无评论...
验证码 换一张
取 消