An instance of a derived class cast to its base class will, of course, invoke a method declared using the 'new keyword
with the same name and signature (parameter Type list) defined in the base class. There is a difference in structure, yes, but not a difference in behavior.
A derived class cast to its base class is-a base class; and it no longer has access to fields, properties, and methods defined in the derived class.
It may help you to think of a stack of dictionaries: in this case the derived class by use of the keyword 'new before the definition of the 'Print method defines a dictionary entry in the dictionary which is "on top:" it hides the definition of 'Print in the base class dictionary.
When you cast an instance of the derived type to the base class, then, essentially you are moving the base-class dictionary to the top, you hide the derived class dictionary, and so, the compiler locates the method bound to the method-name 'Print to execute in the base class dictionary.
Note that you can still execute the method defined in the base class by calling it from within the derived class:
class MyDerivedClass : MyBaseClass
{
new public void Print()
{
Console.WriteLine("This is the derived class.");
base.Print();
}
}
If you want to make a class where you will always use the derived class definition of 'Print:
abstract class MyVirtualBaseClass
{
public virtual void Print()
{
Console.WriteLine("This is the base class.");
}
}
class MyDerivedClass2 : MyVirtualBaseClass
{
public override void Print()
{
Console.WriteLine("This is the derived2 class.");
}
}
MyDerivedClass2 derived2 = new MyDerivedClass2();
MyVirtualBaseClass mybc2 = (MyVirtualBaseClass)derived2;
derived2.Print();
mybc2.Print();
Now you will see that even though the derived class was cast to its base type only the 'Print method in the derived class was called.
It takes some time to get used to these concepts, which are essential to the C# language design.