Suppose we have defined two classes (A and B):
class A
{
public new virtual string ToString()
{
return "I'm class A object.";
}
}
class B : A
{
public override string ToString()
{
return "I'm class B object.";
}
}
If we write:
A a = new B();
Console.WriteLine(a);
"B" (namespace.B
) will be displayed in the console.
That is, the ToString() method of an implicit ancestor of Class A (System.Object.ToString()) will be called.
Why is calling a method of the System.Object class, not class A or B?