Upcasting

The assignment of child class object to a parent class reference in C# inheritance is known as up-casting.

CODE

EG 1 . Creating a child class, parent class and using Upcasting

class Rectangle2D {
    public double length, width;
    public double Area() {
        return length * width;
    }
    public double Perimeter() {
        return 2 * (length+width);
    }
}

class Rectangle3D : Rectangle2D {
    public double height;
    public double Volume() {
        return length * width * height;
    }
}

class Program {
    static void Main() {
        //Upcasting
        Rectangle2D r1 = new Rectangle3D();
    }
}