Concatenate multiple IEnumerable<T>
Use SelectMany
:
public static IEnumerable<T> Concatenate<T>(params IEnumerable<T>[] lists)
{
return lists.SelectMany(x => x);
}
Just for completeness another imo noteworthy approach:
public static IEnumerable<T> Concatenate<T>(params IEnumerable<T>[] List)
{
foreach (IEnumerable<T> element in List)
{
foreach (T subelement in element)
{
yield return subelement;
}
}
}
If you want to make your function work you need an array of IEnumerable:
public static IEnumerable<T> Concartenate<T>(params IEnumerable<T>[] List)
{
var Temp = List.First();
for (int i = 1; i < List.Count(); i++)
{
Temp = Enumerable.Concat(Temp, List.ElementAt(i));
}
return Temp;
}