示例#1
0
        static void Main()
        {
            Shape[] shapes = new Shape[3];
            shapes[0] = new Rectangle(3, 4);
            shapes[1] = new Triangle(3, 4);
            shapes[2] = new Circle(4);

            foreach (var shape in shapes)
            {
                Console.WriteLine("{0}: {1:F2}", shape.GetType().Name, shape.CalculateSurface());
            }
        }
示例#2
0
        static void Main(string[] args)
        {
            Rectangle ret = new Rectangle();
            Circle cir = new Circle();

            float len, bre, rad;
            //Get input data and setup the value in object
            //Then calculate and diplay result using calculate method
            Console.Write("Please enter the Length: ");
            len = Convert.ToInt32(Console.ReadLine());
            Console.Write("Please enter the Breath: ");
            bre = Convert.ToInt32(Console.ReadLine());
            ret.setRectangle(len, bre);
            Calculate(ret);

            Console.Write("Please enter the Radius: ");
            rad = Convert.ToInt32(Console.ReadLine());
            cir.setCircle(rad);
            Calculate(cir);

            Console.ReadKey();
        }