Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Concatenate lists with LINQ

Tags:

c#

Is it possible 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...

?

like image 228
Andreas Brinck Avatar asked Jan 19 '11 11:01

Andreas Brinck


Video Answer


1 Answers

listOfLists.SelectMany( l => l );

full line:

List<int> concatenatedList = listOfLists.SelectMany( l => l ).ToList();
like image 147
Andrey Avatar answered Oct 18 '22 09:10

Andrey