Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public delegate void StartSimulation();
- class EventManager
- {
- public static event StartSimulation startSimulationEvent;
- public static event StartSimulation startSimulation2Event;
- public static event StartSimulation startSimulation3Event;
- public static void OnStartSimulationEvent()
- {
- Console.WriteLine("Called start!!\n");
- if (startSimulationEvent != null)
- startSimulationEvent();
- }
- public static void OnStartSimulation2Event()
- {
- Console.WriteLine("Called start2 on root\n");
- if (startSimulation2Event != null)
- startSimulation2Event();
- }
- }
- class VisitedClass
- {
- public void SubscribeEvent()
- {
- EventManager.startSimulationEvent += SayHello;
- Console.WriteLine("Subscribed!\n");
- }
- void SayHello()
- {
- Console.WriteLine("Hello I have been visited!\n");
- }
- public void UnsubscribeEvent()
- {
- EventManager.startSimulationEvent -= SayHello;
- Console.WriteLine("Unsubscribed!\n");
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- VisitedClass visitedClass = new VisitedClass();
- visitedClass.SubscribeEvent();
- EventManager.OnStartSimulationEvent();
- visitedClass.UnsubscribeEvent();
- EventManager.OnStartSimulationEvent();
- Console.Read();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement