Hi,
new is a short for new slot, that is when you create a virtal method,
all the overrides are using the same slot in the vtable.
when you use new in a deriving class on a virtual method, you kind of
break the virtuality.
for example:
class A
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
object obj = new C();
((C)obj).Print();
((B)obj).Print();
((A)obj).Print();
Console.ReadLine();
/*
C
B
B
*/
}
public virtual void Print()
{
Console.WriteLine("A");
}
}
class B : A
{
public override void Print()
{
Console.WriteLine("B");
}
}
class C : B
{
public new void Print()
{
Console.WriteLine("C");
}
}
when you hold the instance as C, calling the Print will use the new
slot...
when holding the instance as A or B, calling the Print will use the
first slot and will follow the vtable up until B and start from
there...
Eyal.