Guest User

Untitled

a guest
Nov 19th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace EventsExercise
  8. {
  9. public delegate void EventHandler();
  10.  
  11. public class Program
  12. {
  13. public static event EventHandler subscribe;
  14.  
  15. static void Main(string[] args)
  16. {
  17. Button btn1 = new Button("Armando");
  18. subscribe += new EventHandler(btn1.Subscribe);
  19.  
  20. Button btn2 = new Button("Elizabeth");
  21. subscribe += new EventHandler(btn2.Subscribe);
  22.  
  23. subscribe.Invoke();
  24. }
  25. }
  26.  
  27. public class Button
  28. {
  29. public string Name { get; set; }
  30.  
  31. public Button(string name)
  32. {
  33. this.Name = name;
  34. }
  35.  
  36. public void Subscribe()
  37. {
  38. Console.WriteLine($"Succesfully subscribed, {this.Name}");
  39. }
  40. }
  41. }
Add Comment
Please, Sign In to add comment