static void Main() { Triangle triangle = new Triangle(1.1, 2.2, 3.3); Rectangle rectangle = new Rectangle(2.2, 3.2); Circle circle = new Circle(2.2); IShape[] figures = { triangle, rectangle, circle }; foreach (var figure in figures) { Console.WriteLine("Area of this {0} = {1:0.##}", figure.GetType().Name, figure.CalculateArea()); Console.WriteLine("Perimeter of this {0} = {1:0.##}", figure.GetType().Name, figure.CalculatePerimeter()); Console.WriteLine(new string('=', 40)); } }
static void Main(string[] args) { //Testing the shapes : Shape[] shapes = new Shape[3]; shapes[0] = new Triangle(5, 5); shapes[1] = new Rectangle(10, 10); shapes[2] = new Circle(15); //Printing on the console: foreach (var shape in shapes) { Console.WriteLine("The surface of the {0} is {1:F2}.",shape.GetType().Name, shape.CalculateSurface()); } }