1 // The Delegate declaration which defines the signature of methods which can be invoked
2 public delegate void ScoreChangeEventHandler (int newScore, ref bool cancel);
4 // Class which makes the event
6 // Note the use of the event keyword
7 public event ScoreChangeEventHandler ScoreChange;
19 ScoreChange (value, ref cancel);
27 // Class which handles the event
30 public Referee (Game game) {
31 // Monitor when a score changes in the game
32 game.ScoreChange += new ScoreChangeEventHandler (game_ScoreChange);
35 // Notice how this method signature matches the ScoreChangeEventHandler's signature
36 private void game_ScoreChange (int newScore, ref bool cancel) {
38 System.Console.WriteLine ("Good Score");
41 System.Console.WriteLine ("No Score can be that high!");
46 // Class to test it all
49 public static void Main () {
50 Game game = new Game ();
51 Referee referee = new Referee (game);