Ok, I have an some different objects that are derived from a base class and I've put a bunch of them in a list. I want to loop through the list and push each to a method. I have separate methods with each one's type signature, but the compiler is complaining. Can someone explain why? Is this an opportunity to use Generics, and if so, how?
class Base { }
class Level1 : Base { }
class Level2 : Level1 { }
...
List<Base> oList = new List<Base>();
oList.Add(new Level1());
oList.Add(new Level2());
...
...
foreach(Base o in oList)
{
DoMethod(o);
}
...
void DoMethod(Level1 item) { }
void DoMethod(Level2 item) { }
What am I doing wrong?