Concatenate lists with LINQ
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));
精彩评论