static void Main() { Shape[] shapes = new Shape[3] { new Rectangle(4, 3), new Triangle(2, 2), new Circle(2) }; foreach (Shape shape in shapes) { Console.WriteLine(shape); Console.WriteLine(); } }
public override Shape scale(Shape myCircle) { Radius = Radius + 1; return myCircle; }
public abstract Shape scale(Shape x);
public override Shape scale(Shape myRectangle) { Height = Height + 1; Width = Width + 1; return myRectangle; }
public void CallArea(Shape sh) { int a; a = sh.area(); Console.WriteLine("Area: {0}", a); }
//public static bool Contains(this Shape s, Shape t) //{ // if (s is Rectangle && t is Rectangle) return Contains((Rectangle)s, (Rectangle)t); // if (s is Rectangle && t is Circle) return Contains((Rectangle)s, (Circle)t); // if (s is Circle && t is Rectangle) return Contains((Circle)s, (Rectangle)t); // if (s is Circle && t is Circle) return Contains((Circle)s, (Circle)t); // throw new ArgumentException(); //} // ↑before // ↓after public static bool Contains(this Shape s, Shape t) { return Contains((dynamic)s, (dynamic)t); }