public class Rectangle {
public virtual int Width { get; set; }
public virtual int Height { get; set; }
public Rectangle() {}
public Rectangle(int width, int height) {
Width = width;
Height = height;
}
public override string ToString() {
return $"{nameof(Width)}: {Width}, {nameof(Height)}: {Height}";
}
}
public class Square : Rectangle {
public override int Width {
set { base.Width = base.Height = value; }
}
public override int Height {
set { base.Width = base.Height = value; }
}
}
public class Program {
public static int Area(Rectangle r) => r.Width * r.Height;
public static void Main() {
Rectangle rc = new Rectangle();
System.Console.WriteLine($"{rc} has area {Area(rc)}");
Rectangle sq = new Square();
sq.Width = 4;
System.Console.WriteLine($"{sq} has area {Area(sq)}");
}
}