Advertisement
Guest User

Melmacaltiel

a guest
Aug 26th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 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. delegate int NumberChanger(int n);
  8. namespace Delegates
  9. {
  10. class TestDelegate
  11. {
  12. static int num = 10;
  13. public static int AddNum(int p)
  14. {
  15. num += p;
  16. return num;
  17. }
  18. public static int MultNum(int q)
  19. {
  20. num *= q;
  21. return num;
  22. }
  23. public static int getNum()
  24. {
  25. return num;
  26. }
  27.  
  28. static void Main(string[] args)
  29. {
  30. NumberChanger nc;
  31. NumberChanger nc1 = new NumberChanger(AddNum);
  32. NumberChanger nc2 = new NumberChanger(MultNum);
  33. nc = nc1;
  34. nc -= nc2;
  35.  
  36. nc(5);
  37. Console.WriteLine("Value of Num: {0}", getNum());
  38.  
  39. Console.ReadKey();
  40. Console.Read();
  41. }
  42. }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement