Initial Revision
[ohcount] / test / expected_dir / cs1.cs / csharp / code
1 public delegate void ScoreChangeEventHandler (int newScore, ref bool cancel);
2 public class Game {
3 public event ScoreChangeEventHandler ScoreChange;
4 int score;
5 public int Score {
6 get {
7 return score;
8 }
9 set {
10 if (score != value) {
11 bool cancel = false;
12 ScoreChange (value, ref cancel);
13 if (! cancel)
14 score = value;
15 }
16 }
17 }
18 }
19 public class Referee
20 {
21 public Referee (Game game) {
22 game.ScoreChange += new ScoreChangeEventHandler (game_ScoreChange);
23 }
24 private void game_ScoreChange (int newScore, ref bool cancel) {
25 if (newScore < 100)
26 System.Console.WriteLine ("Good Score");
27 else {
28 cancel = true;
29 System.Console.WriteLine ("No Score can be that high!");
30 }
31 }
32 }
33 public class GameTest
34 {
35 public static void Main () {
36 Game game = new Game ();
37 Referee referee = new Referee (game);
38 game.Score = 70;
39 game.Score = 110;
40 }
41 }