fork(1) download
  1. using System;
  2.  
  3. public class EventExample
  4. {
  5. public event Handler SomeEvent;
  6.  
  7. public static void Main()
  8. {
  9. var example = new EventExample();
  10. example.SomeEvent += Handler1;
  11. Console.WriteLine("-- One Handler --");
  12. example.SomeEvent();
  13.  
  14. example.SomeEvent += Handler2;
  15. Console.WriteLine("-- Two Handlers --");
  16. example.SomeEvent();
  17.  
  18. example.SomeEvent = Handler3;
  19. Console.WriteLine("-- One Handler? --");
  20. example.SomeEvent();
  21. }
  22.  
  23. public static void Handler1()
  24. {
  25. Console.WriteLine("In 1");
  26. }
  27.  
  28. public static void Handler2()
  29. {
  30. Console.WriteLine("In 2");
  31. }
  32.  
  33. public static void Handler3()
  34. {
  35. Console.WriteLine("In 3");
  36. }
  37. }
  38.  
  39. public delegate void Handler();
Success #stdin #stdout 0.02s 24112KB
stdin
Standard input is empty
stdout
-- One Handler --
In 1
-- Two Handlers --
In 1
In 2
-- One Handler? --
In 3