I have two collections in my program: List<BaseClass> and List<DerivedClass>. I often need to cycle through both collections. It's so tedious to write 2 cycles every time:
foreach (BaseClass obj in baseClassList)
; //Do something
foreach (DerivedClass obj in derivedClassList)
; //Do exactly the same thing
I thought, since the objects in the second collection are of a derived class, and not just completely unrelated class, there should be some more elegant way to write this piece of code. Also, I'm concerned with performance, of course: I guess creating a
3rd list and copying all the objects from the 1st and 2nd list into the 3rd list doesn't sound like a good idea. Please, help me!
View Complete Post