Guest User

Untitled

a guest
Oct 16th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace EventsPractice
  7. {
  8. public delegate void myEventHandler(string newValue);
  9.  
  10. public class EventExample
  11. {
  12. private string _value;
  13. public event myEventHandler valueChanged;
  14.  
  15. public string val
  16. {
  17. set
  18. {
  19. _value = value;
  20. valueChanged(_value);
  21. }
  22. }
  23.  
  24. static void myEvt_valueChanged(string newValue)
  25. {
  26. Console.WriteLine("The value changed to {0}", newValue);
  27. }
  28. }
  29. }
  30.  
  31. using System;
  32. using System.Collections.Generic;
  33. using System.Linq;
  34. using System.Text;
  35. using EventsPractice;
  36.  
  37. namespace EventsPractice
  38. {
  39. public class Program
  40. {
  41. static void Main(string[] args)
  42. {
  43. EventExample myEvt = new EventExample();
  44.  
  45. myEvt.valueChanged += myEventHandler(myEvt_valueChanged);
  46.  
  47. string str;
  48. do
  49. {
  50. str = Console.ReadLine();
  51. if (!str.Equals("exit"))
  52. myEvt.val = str;
  53. } while (!str.Equals("exit"));
  54.  
  55. }
  56. }
  57. }
Add Comment
Please, Sign In to add comment