RoflcoptrException RoflcoptrException - 3 months ago 15
C# Question

Using foreach loop to iterate through two lists

I have two lists

List<object> a = new List<object>();
List<object> b = new List<object>();


Now i want to iterate through the elements of both list. I could do that by writing a foreach loop for each list. But is it also possible to do something like that?

foreach(object o in a, b) {
o.DoSomething();
}


It would also be nice if something like that would be possible:

foreach (object o in a && b) {
o.DoSomething();
}

Answer
foreach(object o in a.Concat(b)) {
 o.DoSomething();
}