Conversions of Classes (Reference Types):To the Base Class of an Object
using System;
class Base
{
public virtual void WhoAmI()
{
Console.WriteLine("Base");
}
}
class Derived: Base
{
public override void WhoAmI()
{
Console.WriteLine("Derived");
}
}
publicclass TotheBaseClassofanObject {
publicstaticvoid Main()
{
Derived d = new Derived();
Base b = d;
b.WhoAmI();
Derived d2 = (Derived) b;
object o = d;
Derived d3 = (Derived) o;
}
}