static void Main()
        {
            var shapes = new List <IShape>
            {
                new Square(3),
                new Square(5),

                new Rectangle(10, 5),
                new Rectangle(13, 2.4),
                new Rectangle(3, 5),

                new Triangle(0, 0, 2, 3, 5, 4),
                new Triangle(3, 2, 5, 7, 8, 1),

                new Circle(2.9),
                new Circle(4.1),
                new Circle(0)
            };

            var firstAreaShape = FindByMaxArea(shapes, 0);

            Console.WriteLine($"Первая по площади фигура: {firstAreaShape}");
            var secondAreaShape = FindByMaxArea(shapes, 1);

            Console.WriteLine($"Вторая по площади фигура: {secondAreaShape}");

            Console.WriteLine();
            var firstPerimeterShape = FindByMaxPerimeter(shapes, 0);

            Console.WriteLine($"Первая по периметру фигура: {firstPerimeterShape}");
            var secondPerimeterShape = FindByMaxPerimeter(shapes, 1);

            Console.WriteLine($"Вторая по периметру фигура: {secondPerimeterShape}");

            Console.WriteLine();
            Console.WriteLine("Сравнение фигур с помощью переопределенного метода Equals:");
            var circle1 = new Circle(2.4);
            var circle2 = new Circle(3.87);
            var circle3 = new Circle(2.4);
            var square1 = new Square(2.4);

            Console.WriteLine($"{nameof(circle1)} - {circle1}");
            Console.WriteLine($"{nameof(circle2)} - {circle2}");
            Console.WriteLine($"{nameof(circle3)} - {circle3}");
            Console.WriteLine($"{nameof(square1)} - {square1}");

            Console.WriteLine();
            Console.WriteLine($"Фигура {nameof(circle2)} {(circle1.Equals(circle2) ? "равна" : "не равна")} фигуре {nameof(circle1)}");
            Console.WriteLine($"Фигура {nameof(circle3)} {(circle1.Equals(circle3) ? "равна" : "не равна")} фигуре {nameof(circle1)}");
            Console.WriteLine($"Фигура {nameof(square1)} {(circle1.Equals(square1) ? "равна" : "не равна")} фигуре {nameof(circle1)}");

            Console.ReadLine();
        }
Example #2
0
        static void Main(string[] args)
        {
            #region Circles
            // create new Circle
            Circle c1 = new Circle();
            Circle c2 = new Circle();
            Circle c3 = new Circle();

            // ToString tests
            Console.WriteLine("Circle1:\n" + c1.ToString());
            Console.WriteLine("Circle2:\n" + c2.ToString());
            Console.WriteLine("Circle3:\n" + c3.ToString());

            // Equals tests
            Console.WriteLine("Does Circle1 equal Circle2? {0}", c1.Equals(c2));
            Console.WriteLine("Does Circle1 equal Circle3? {0}", c1.Equals(c3));
            Console.WriteLine("Does Circle2 equal Circle3? {0}", c2.Equals(c3) + "\n");
            #endregion

            #region Squares
            // create new Squares
            Square s1 = new Square();
            Square s2 = new Square();
            Square s3 = new Square();

            // ToString tests
            Console.WriteLine("Square1:\n" + s1.ToString());
            Console.WriteLine("Square2:\n" + s2.ToString());
            Console.WriteLine("Square3:\n" + s3.ToString());

            // Equals tests
            Console.WriteLine("Does Square1 equal Square2? {0}", s1.Equals(s2));
            Console.WriteLine("Does Square1 equal Square3? {0}", s1.Equals(s3));
            Console.WriteLine("Does Square2 equal Square3? {0}", s2.Equals(s3) + "\n");
            #endregion

            Console.ReadLine();
        }