Пример #1
0
        static void Main(string[] args)
        {
            var quad1 = new Quad(3, 7, 4, 5);

            Console.WriteLine($"quad1 perimeter is {quad1.GetPerimeter()},\n    and area is unknown,\n    print is {quad1.Print()}.\n");

            var rect1 = new Rect(3, 7);

            Console.WriteLine($"rect1 perimeter is {rect1.GetPerimeter()},\n    and area is {rect1.GetArea()},\n    print is {rect1.Print()}.\n");

            var sqr1 = new Sqr(5);

            Console.WriteLine($"sqr1 perimeter is {sqr1.GetPerimeter()},\n    and area is {sqr1.GetArea()},\n    print is {sqr1.Print()}.\n");

            var poly = new Quad[] { sqr1, rect1, quad1 };

            foreach (var quad in poly)
            {
                Console.WriteLine($"Type is {quad.Print()}.");

                // needed b/c there is no GetArea() method for Quad class
                var rect = quad as Rect;
                if (rect != null)
                {
                    Console.WriteLine($"The shape has an area of {rect.GetArea()}.\n");
                }
            }
        }
        static void Main(string[] args)
        {
            var sqr1 = new Sqr(7);

            Console.WriteLine($" SQR: Perimeter is {sqr1.Perimeter() }");
            Console.WriteLine($" SQR: Area is {sqr1.Area() }");

            var rect1 = new Rect(5, 7);

            // up above now works and it less work becasue of the work we did on the Rect class with the base attached to our methods
            //rect1.Side1 = 3;
            //rect1.Side2 = 4;
            //rect1.Side3 = 5;
            //rect1.Side4 = 6;
            Console.WriteLine($"Perimeter is {rect1.Perimeter() }");
            Console.WriteLine($"Area is {rect1.Area() }");
            //Console.WriteLine($"About is {rect.About});
        }