Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IEnumerable<IEnumerable<T>> to IEnumerable<T> using LINQ

How to split an IEnumerable of IEnumerables to one flat IEnumerable using LINQ (or someway else)?

like image 802
abatishchev Avatar asked Apr 09 '10 21:04

abatishchev


People also ask

Can you use Linq on IEnumerable?

All LINQ methods are extension methods to the IEnumerable<T> interface. That means that you can call any LINQ method on any object that implements IEnumerable<T> . You can even create your own classes that implement IEnumerable<T> , and those classes will instantly "inherit" all LINQ functionality!

What is IEnumerable T in C#?

IEnumerable. IEnumerable<T> contains a single method that you must implement when implementing this interface; GetEnumerator, which returns an IEnumerator<T> object. The returned IEnumerator<T> provides the ability to iterate through the collection by exposing a Current property.

What is meant by Linq in C#?

Language-Integrated Query (LINQ) is the name for a set of technologies based on the integration of query capabilities directly into the C# language. Traditionally, queries against data are expressed as simple strings without type checking at compile time or IntelliSense support.

What is IQueryable and IEnumerable in C#?

The major difference between IQueryable and IEnumerable is that IQueryable executes query with filters whereas IEnumerable executes the query first and then it filters the data based on conditions.


2 Answers

enumerable.SelectMany(x => x)
like image 124
mmx Avatar answered Oct 13 '22 01:10

mmx


var result = from e in enumerables
             from v in e
             select v;
like image 26
pdr Avatar answered Oct 13 '22 01:10

pdr