I have a class which inherits from a class which inherits from a class (and a few more in the original code :)).
How do I call from an override to one of the top most parents? Here is a code sample:
class Program
{
static void Main(string[] args)
{
Animal a = new Animal();
a.DoSomething();
Predator p = new Predator();
p.DoSomething();
Cat c = new Cat();
c.DoSomething();
}
}
class Animal
{
public virtual void DoSomething()
{
Console.WriteLine("Animal");
}
}
class Predator : Animal
{
public override void DoSomething()
{
Console.WriteLine("Predator");
}
}
class Cat : Predator
{
public override void DoSomething()
{
base.DoSomething();
//Console.WriteLine("Cat");
}
}
I want that when I call c.DoSomething() method I will get "Animal" as a result.
Thanks to all