コード例 #1
0
        static void Main(string[] args)
        {
            Footballer Lionella = new Footballer();

            Lionella.SalaryNotify += salary => Console.WriteLine($"Current salary: {salary}\n");
            for (int i = 0; i < 10; i++)
            {
                try
                {
                    Lionella.DopingTest();
                    Lionella.Compete();
                }
                catch (Exception details)
                {
                    Console.WriteLine(details.Message);
                }
            }
            Weightlifter Tolya = new Weightlifter();

            Tolya.MedalNotify += delegate(int bronzeMedals, int silverMedals, int goldMedals)
            {
                Console.WriteLine($"Current medals:\nGold: {goldMedals}\nSilver: {silverMedals}\nBronze: {bronzeMedals}\n");
            };
            for (int i = 0; i < 10; i++)
            {
                try
                {
                    Tolya.DopingTest();
                    Tolya.Compete();
                }
                catch (Exception details)
                {
                    Console.WriteLine(details.Message);
                }
            }
            Athlete Matvey = new Athlete();

            try
            {
                Matvey.Compete();
            }
            catch (Exception details)
            {
                Console.WriteLine(details.Message);
            }
            Matvey.Specialization = "Javelin-throwing";
            try
            {
                Matvey.Compete();
            }
            catch (Exception details)
            {
                Console.WriteLine(details.Message);
            }
            Console.ReadKey();
        }
コード例 #2
0
        public new int CompareTo(object s)
        {
            Weightlifter subject = s as Weightlifter;

            if (subject != null)
            {
                return(this.weight.CompareTo(subject.weight));
            }
            else
            {
                throw new Exception("Unable to compare these objects");
            }
        }