コード例 #1
0
        static void Main(string[] args)
        {
            // Создание первого экземпляра класса Parrot
            Parrot p1 = new Parrot("Tim", 0.5, 10, 4);
            // Создание второго экземпляра класса Parrot
            Parrot p2 = new Parrot("Max", 0.4, 12, 5);

            p1.ShowInfoAboutFeather();
            p2.ShowInfoAboutFeather();

            Parrot p3 = p1 - p2;

            Console.WriteLine($"\nРазность в показателях жизнедеятельности птицы породы {p3.GetType().Name} " +
                              $"по кличке <<{p1.Nickname}>> и <<{p2.Nickname}>> следующая:\n" +
                              $"в скорости бега:\t{p3.SpeedOfRun}\n" +
                              $"в высоте полета:\t{p3.HightOfFlight}\n" +
                              $"в продолжительности сна: {p3.PeriodOfSleep}\n");

            Parrot p4 = new Parrot();

            p4          = ++p1;
            p4.Nickname = "Kuzya";
            p4.ShowInfoAboutFeather();

            Parrot p5 = p1 * p2;

            p5.Nickname = "Roma";
            p5.ShowInfoAboutFeather();
        }
コード例 #2
0
        public static Parrot operator -(Parrot a, Parrot b)
        {
            Parrot result = new Parrot();

            result.SpeedOfRun    = (a.SpeedOfRun > b.SpeedOfRun) ? (a.SpeedOfRun - b.SpeedOfRun) : (b.SpeedOfRun - a.SpeedOfRun);
            result.HightOfFlight = (a.HightOfFlight > b.HightOfFlight) ? (a.HightOfFlight - b.HightOfFlight) : (b.HightOfFlight - a.HightOfFlight);
            result.PeriodOfSleep = result.PeriodOfSleep = (a.PeriodOfSleep > b.PeriodOfSleep) ? (a.PeriodOfSleep - b.PeriodOfSleep) : (b.PeriodOfSleep - a.PeriodOfSleep);
            return(result);
        }