I have an exercise that I have to create an IAnimal interface and two classes that use that Dog and Cat , because in the interface I have to create get set named Name and a method that returns a string called SaySomething, the question is that in the exercise I have to create in the Main an object type IAnimal already Through a combination of loop and switch case I have to enter data to the two classes Dog and Cat but I get a compilation error. This is a part of my code from the Main:
IAnimal []animal=new IAnimal [3];
char ch;
int i = 3;
while (i != 0)
{
Console.WriteLine("Its a dog or cat? (d/c)");
ch = char.Parse( Console.ReadLine());
Console.WriteLine("What its her name?");
string name = Console.ReadLine();
Console.WriteLine("How he does?");
string voice = Console.ReadLine();
switch (ch)
{
case 'd':
animal[i] = new Dog(name,voice);
break;
case 'c':
animal[i] = new Cat(name,voice);
break;
default:
Console.WriteLine("Default case");
continue;
}
i--;
}