using System;
public class Program
{
public static void Main()
Text text = new Text();
//Upcasting
Shape shape1 = text;
text.Height = 100;
shape1.Height = 120;
shape1.Draw();
//Upcasting End
//Downcasting
Shape s1 = new Text();
Text t1 = (Text)s1;
Text t2 = s1 as Text; //This is better
//Console.WriteLine(s1.FontName); You cannot do this.
t1.FontName = "Arial";
Console.WriteLine(t1.FontName);
//Downcasting End
}
public class Shape
public int Width
get;
set;
public int Height
public int XPos
public int YPos
public void Draw()
Console.WriteLine("Drawing from {0} and {1} of Width {2} and Height {3}", Width, Height, XPos, YPos);
public class Text : Shape
public string FontSize
public string FontName