I have this situation:
class Animal
{
int size;
}
class Dog : Animal
{
string Name;
}
class Cat : Animal
{
string Alias;
}
public void Check( Dictionary<string,Animal> animals )
{
foreach(var pet in animals){...}
}
My question is here:
if Dog extends animal why the Ditionary does not recognize a Dog as Animal?
Do you have ideas that allows pass a Dictionary of child class and iterate it (whitout use the treat Dictionary of (string,object) ) ?
public void MySituation()
{
Dictionary<string,Animal> dogs = new Dictionary<string,Dog>();
** ERROR 01**
Dictionary<string,Cat> cats = new Dictionary<string,Cat>();
Check(cats);
** ERROR 02**
}
Thanks very much. That compiler optimization power be with you.