Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Threading;
- namespace events
- {
- public class AirCraftParameters : EventArgs
- {
- public AirCraftParameters(int alt, int speed)
- {
- Altitude = alt;
- Speed = speed;
- }
- public readonly int Altitude;
- public readonly int Speed;
- }
- public class Ground
- {
- public static void GroundHandler(object obj, AirCraftParameters e)
- {
- Console.WriteLine(obj.ToString()+", it's the Ground, your parameters: alt="+e.Altitude+", speed="+e.Speed);
- }
- }
- public class B737
- {
- public void b737Handler(object obj, AirCraftParameters e)
- {
- Console.WriteLine(obj.ToString() + ", it's Boeing737, all OK!");
- }
- }
- public class A300
- {
- public void a300Handler(object obj, AirCraftParameters e)
- {
- Console.WriteLine(obj.ToString() + ", it's AirbusA300, everything's perfect!");
- }
- }
- //public delegate void AircraftEventHandler(object sender, AirCraftParameters e);
- public class B787
- {
- public override string ToString()
- {
- return "Boeing787";
- }
- public event EventHandler<AirCraftParameters> TheSituationEvent;
- public void CheckTheSituation()
- {
- int times = 1;
- Console.WriteLine("Checking...");
- for (int i = 0; i < times; i++)
- {
- TheSituationEvent?.Invoke(this,new AirCraftParameters(35000, 260));
- System.Threading.Thread.Sleep(1000);
- }
- Console.WriteLine("Connection successfully disrupted");
- }
- }
- internal class Program
- {
- public static void Main(string[] args)
- {
- B787 b787 = new B787();
- B737 b737 = new B737();
- A300 a300 = new A300();
- b787.TheSituationEvent += Ground.GroundHandler;
- b787.TheSituationEvent += b737.b737Handler;
- b787.TheSituationEvent += a300.a300Handler;
- b787.CheckTheSituation();
- b787.TheSituationEvent -= Ground.GroundHandler;
- Console.WriteLine("*** communication with the earth is lost");
- b787.CheckTheSituation();
- b787.TheSituationEvent -= b737.b737Handler;
- b787.TheSituationEvent -= a300.a300Handler;
- Console.WriteLine("*** communication with other aircrafts is lost");
- b787.CheckTheSituation();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement