Concat
Returns a new collection that contains the elements of each the collection in order.
Parameters
Returns
IEnumerable<IEnumerable<T>> sources
IEnumerable<T>
params IEnumerable<T>[ ] sources
IEnumerable<T>
Usage
There's two different overloads of this function, but they works in a very similar way.
The first one requires that the parameter is an IEnumerable
of IEnumerables
and the second one uses the params
keyword to provides a way to inform multiples standalone IEnumerables
.
Concatenating an IEnumerable of IEnumerabls
//IEnumerable<IEnumerable<int>> sources =
// { { 1, 2, 3, 4, 5 }, { 6, 7, 8, 9, 10 } }
IEnumerable<int> result = sources.Concat()
//result = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }
Concatenating three different collections
//IEnumerable<int> first = { 6, 7, 8, 9, 10 }
//IEnumerable<int> second = { 1, 2, 3, 4, 5 }
//IEnumerable<int> third = { 2, 4, 6, 8, 10 }
IEnumerable<int> result = first.Concat(second, third);
//result = { 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 2, 4, 6, 8, 10 }
Last updated
Was this helpful?