10. What is C#?
There are two more casting terms Upcasting and Downcasting. basically these are parts of Implicit conversion and Explicit conversion.
Implicit conversion of derived classes to base class is called Upcasting and Explicit conversion of base class to derived classes is called Downcasting.
class Base
{
public int num1 { get; set; }
}
class Derived : Base
{
public int num2 { get; set; }
}
class Program
{
static void Main(string[] args)
{
Derived d1 = new Derived();
//Upcasting
Base b1 = d1;
Base b2 = new Base();
//Downcasting
Derived d2 = (Derived)b2;
}
}