public Person(string name, ClockTower tower ) { _name = name; _tower = tower; _tower.Chime += (object sender, ClockTowerEventArgs args) => { Console.WriteLine("{0} heard the clock chime.", _name); switch(args.Time) { case 6: Console.WriteLine("{0} is waking up.", _name); break; case 17: Console.WriteLine("{0} is going home.", _name); break; } }; }
public Person(string name, ClockTower tower) { _name = name; _tower = tower; _tower.Chime += (object sender, ClockTowerEventArgs args) => { Console.WriteLine("{0} heard the clock chime!", _name); switch (args.Time) { case 6: Console.WriteLine("{0} is waking up", _name); break; case 17: Console.WriteLine("{0} is going home from work", _name); break; } }; }
static void Main(string[] args) { var tower = new ClockTower(); var john = new Person("John", tower); tower.ChimeSixAM(); Console.ReadLine(); }