How can I create a list of classes in C# to iterate over in a loop
Posted
by Jean-Bernard Pellerin
on Stack Overflow
See other posts from Stack Overflow
or by Jean-Bernard Pellerin
Published on 2010-05-06T21:34:54Z
Indexed on
2010/05/06
21:48 UTC
Read the original article
Hit count: 239
Suppose I have class animal
and classes cat
and dog
extending it. I want to do something along the lines of:
foreach (animal a in {cat, dog})
if (a.isValid(parameters))
doStuff();
My only alternative is a switch statement for each class, something I'd like to avoid.
Thanks,
J-B
© Stack Overflow or respective owner