Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Kolos_zad2
- {
- delegate bool Warunek(int i, int j);
- delegate int Delegacja(int i, int j);
- class A
- {
- public event Delegacja SieDzieje;
- public int x = 2;
- public void DoRoboty(int i)
- {
- if (SieDzieje != null)
- x += SieDzieje(x, i);
- else x -= 1;
- }
- }
- class Test
- {
- static void Main(string[] args)
- {
- A a = new A();
- a.DoRoboty(1);
- Console.WriteLine("{0}", a.x);
- Warunek w = (x, y) => (x < y);
- Delegacja fst = (x, y) =>
- {
- Console.WriteLine($"fst: {x + y}");
- return (w(x, y) ? x + y : x - y);
- };
- a.SieDzieje += fst;
- a.DoRoboty(2);
- w += (x, y) =>
- {
- Console.WriteLine($"W: {x + y}");
- return (x > y);
- };
- Console.WriteLine("{0}", a.x);
- Delegacja snd = (x, y) => w(x, y) ? x + 1 : y + 2;
- a.SieDzieje += snd;
- a.DoRoboty(3);
- Console.WriteLine("{0}", a.x);
- a.SieDzieje -= fst;
- a.DoRoboty(a.x);
- Console.WriteLine("{0}", a.x);
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment