Hello, I've some classes like this
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
A a = new C();
a.method();
Console.ReadLine();
}
}
public class A
{
public virtual void method()
{
Console.WriteLine("METHOD FROM A");
}
}
public class B : A { }
public class C : B
{
public override void method()
{
Console.WriteLine("METHOD FROM C");
}
}
}
It works correctly, prints "METHOD FROM C"
BUT
if I've a situation like this
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
A a = new C();
a.method();
Console.ReadLine();
}
}
public class A
{
public void method()
{
Console.WriteLine("METHOD FROM A");
}
}
public class B : A { }
public class C : B
{
public new void method()
{
Console.WriteLine("METHOD FROM C");
}
}
}
it prints "METHOD FROM A". How can I obtain the same behaviour of first example without adopt cast or change method declaration with override?