abatishchev
abatishchev

Reputation: 100366

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

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

Upvotes: 21

Views: 7197

Answers (3)

Jay
Jay

Reputation: 57979

IEnumerable<IEnumerable<int>> number_collections = ...
IEnumerable<int> collection = number_collections.SelectMany(x => x);

Upvotes: 8

pdr
pdr

Reputation: 6440

var result = from e in enumerables
             from v in e
             select v;

Upvotes: 13

Mehrdad Afshari
Mehrdad Afshari

Reputation: 422290

enumerable.SelectMany(x => x)

Upvotes: 57

Related Questions