Further to the (correct) LINQ-based answers...
If you don't want to use LINQ, you can invent a ChainedEnumerable class, using yield:
public class ChainedEnumerable<T> : IEnumerable<T>
{
private readonly IEnumerable<T>[] _inners;
public ChainedEnumerable(params IEnumerable<T>[] inners)
{
_inners = inners;
}
public IEnumerator<T> GetEnumerator()
{
foreach (IEnumerable<T> inner in _inners)
{
foreach (T t in inner)
{
yield return t;
}
}
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
}
Use it like this:
List<string> a = new List<string> { "A1", "A2", "A3" };
List<string> b = new List<string> { "B1", "B2", "B3" };
ChainedEnumerable<string> chainedEnumerable =
new ChainedEnumerable<string>(a, b);
foreach (string s in chainedEnumerable)
Console.WriteLine(s);