Example #1
0
        // Create a method that will subscribe. This method needs to have the same signature as our delegate
        public static void KilledEnemy(object sender, ShotsFiredEventArgs e)
        {
            var tempSender = sender as Shooter; // This transforms our sender object into Shooter

            Console.WriteLine("I killed an enemy!");
            Console.WriteLine($"Time of kill is {e.TimeOfKill}");
            Console.WriteLine($"My score is now {score} by {tempSender.Name}");
        }
Example #2
0
 // Subscriber methods to the event
 static void KilledEnemy(object source, ShotsFiredEventArgs e)
 {
     Console.WriteLine($"I killed an enemy at {e.TimeOfKill.TimeOfDay}!");
     Console.WriteLine($"My score is now {score}");
 }