Linq list of lists to single list

Solution 1:

You want to use the SelectMany extension method.

var residences = details.SelectMany(d => d.AppForm_Residences).ToList();

Solution 2:

Use SelectMany

var all = residences.SelectMany(x => x.AppForm_Residences);

Solution 3:

Here is a sample code for you:

List<int> listA = new List<int> { 1, 2, 3, 4, 5, 6 };

List<int> listB = new List<int> { 11, 12, 13, 14, 15, 16 };

List<List<int>> listOfLists = new List<List<int>> { listA, listB };

List<int> flattenedList = listOfLists.SelectMany(d => d).ToList();

foreach (int item in flattenedList)
{
    Console.WriteLine(item);
}

And the out put will be:

1
2
3
4
5
6
11
12
13
14
15
16
Press any key to continue . . .

Solution 4:

And for those that want the query expression syntax: you use two from statements

var residences = (from d in details from a in d.AppForm_Residences select a).ToList();