static void Main(string[] args) { CountDounTimer timer = new CountDounTimer(); timer.TimeEvent += delegate(string s) { if (s == "Who wants to go to the theater?") { Console.WriteLine("I am a happy subscriber number 1."); } else { Console.WriteLine("No, thanks. I am sad subcriber number 1. I wants to go to the theater."); } }; timer.TimeEvent += Subscriber; timer.TimeEvent += (string s) => { if (s == "Who wants to go for a cup of coffe?") { Console.WriteLine("I am a happy subscriber number 2."); } else { Console.WriteLine("No, thanks. I am sad subcriber number 2. I wants to go for a cup of coffe."); } }; CarefreeMan man = new CarefreeMan(timer); timer.OnDounTimer(3, "Who wants to go to the theater?"); Console.WriteLine(); timer.OnDounTimer(4, "Who wants to go for a cup of coffe?"); Console.WriteLine(); timer.OnDounTimer(2, "Who wants to go to tennis?"); timer.TimeEvent -= Subscriber; Console.WriteLine(); timer.OnDounTimer(1, "Who wants to go for a cup of coffe?"); }
public CarefreeMan(CountDounTimer timer) { timer.TimeEvent += EntertainingProgram; }