Exemple #1
0
        static void AnonymousMethod()
        {
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine("=> Anonymous Method");

            int methoder = 1;

            CarCustom c1 = new CarCustom("SlugOne", 80, 10);

            c1.AboutToBlow += delegate { methoder++; Console.WriteLine("Eek! Going too fast!"); };
            c1.AboutToBlow += delegate(object sender, CarEventArgs e){
                methoder++;
                Console.WriteLine($"Message from Car: {e.msg} at {e.time}. {methoder}");
            };
            c1.Exploaded += delegate(object sender, CarEventArgs e) {
                methoder++;
                ConsoleColor fore = Console.ForegroundColor;
                Console.ForegroundColor = ConsoleColor.DarkYellow;
                Console.WriteLine($"Fatal Message from Car: {e.msg} at {e.time}. {classer} / {methoder}");
                Console.ForegroundColor = fore;
            };

            Console.WriteLine("===== Speeding up");
            for (int i = 0; i < 6; i++)
            {
                c1.Accelerate(20);
            }
        }
Exemple #2
0
        static void CustomArgs()
        {
            Console.ForegroundColor = ConsoleColor.DarkCyan;
            Console.WriteLine("=> Custom Event Arguments");

            CarCustom c1 = new CarCustom("SlugBug", 100, 10);

            c1.AboutToBlow += CarIsAlmostDoomed;
            c1.AboutToBlow += CarAboutToBlow;
            c1.Exploaded   += CarExploded;

            Console.WriteLine("===== Speeding up");
            for (int i = 0; i < 7; i++)
            {
                c1.Accelerate(20);
            }
        }