Is there a simple built-in way to take an ordered list of IEnumerable
s and return a single IEnumerable
which yields, in order, all the elements in the first, then the second, and so on.
I could certainly write my own, but I wanted to know whether there was already a way to accomplish this seemingly useful task before I do it.
Try SelectMany.
IEnumerable<int> Collapse(IEnumerable<IEnumerable<int>> e){
return e.SelectMany(x => x );
}
The purpose of this function is to flatten a group of IEnumerable<IEnumerable<T>> into an IEnumerable<T>. The returned data will preserve the original order.
Further to JaredPar's (correct) answer - also query syntax:
var all = from inner in outer
from item in inner
select item;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With