This post will discuss how to flatten a list of lists in C#.

1. Using Enumerable.SelectMany() method (System.Linq)

We can use LINQ’s SelectMany() method to map each element of a list to an IEnumerable<T> and flattens the resulting sequences into a single list. The following code example demonstrates how to use the SelectMany to flatten a list.

Download  Run Code

2. Using LINQ Query Expressions

The following code example shows how to use LINQ query expressions to flatten a list:

Download  Run Code

That’s all about flattening a list of lists in C#.