Guest User

Untitled

a guest
Dec 6th, 2018
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 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 Kolos_zad2
  8. {
  9.  
  10. delegate bool Warunek(int i, int j);
  11. delegate int Delegacja(int i, int j);
  12. class A
  13. {
  14. public event Delegacja SieDzieje;
  15. public int x = 2;
  16. public void DoRoboty(int i)
  17. {
  18. if (SieDzieje != null)
  19. x += SieDzieje(x, i);
  20. else x -= 1;
  21. }
  22. }
  23. class Test
  24. {
  25. static void Main(string[] args)
  26. {
  27. A a = new A();
  28. a.DoRoboty(1);
  29. Console.WriteLine("{0}", a.x);
  30. Warunek w = (x, y) => (x < y);
  31. Delegacja fst = (x, y) =>
  32. {
  33. Console.WriteLine($"fst: {x + y}");
  34. return (w(x, y) ? x + y : x - y);
  35. };
  36. a.SieDzieje += fst;
  37. a.DoRoboty(2);
  38. w += (x, y) =>
  39. {
  40. Console.WriteLine($"W: {x + y}");
  41. return (x > y);
  42. };
  43. Console.WriteLine("{0}", a.x);
  44. Delegacja snd = (x, y) => w(x, y) ? x + 1 : y + 2;
  45. a.SieDzieje += snd;
  46. a.DoRoboty(3);
  47. Console.WriteLine("{0}", a.x);
  48. a.SieDzieje -= fst;
  49. a.DoRoboty(a.x);
  50. Console.WriteLine("{0}", a.x);
  51. Console.ReadKey();
  52. }
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment