コード例 #1
0
ファイル: TestShapes.cs プロジェクト: quela/myprojects
        static void Main()
        {
            //Create array of shapes
            Shape[] shapesArr = new Shape[] {
            new Triangle(4,2),
            new Rectangle(2.5 , 3.5),
            new Circle(2.2)};

            //Print shape name and surface
            foreach (var shape in shapesArr)
            {
                Console.WriteLine("{0} surface is {1:f2}",shape.GetType().Name, shape.CalculateSurface(shape.Width, shape.Height));
            }
        }
コード例 #2
0
        static void Main(string[] args)
        {
            // create a few shapes
            Shape[] shapes = new Shape[]
            {
                new Rectangle(10, 15),
                new Triangle(17.5, 4),
                new Circle(8, 8),
                new Triangle(17, 9)
            };

            // print all surfaces
            for(int i = 0; i < shapes.Length; i ++)
            {
                Console.WriteLine("Shape {0} surface: {1}", i, shapes[i].CalculateSurface());
            }
        }