Advertisement
Pentium320

kolo3

Nov 23rd, 2018
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.00 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 Zad4A
  8. {
  9.     public delegate int F(int x);
  10.     class Funkcje
  11.     {
  12.         public event F fcja;
  13.         static String msg = "";
  14.         public static int jeden(int x)
  15.         {
  16.             msg += $"jeden({x}) = (x+1) ";
  17.             return x + 1;
  18.         }
  19.         public static int dwa(int x)
  20.         {
  21.             msg += $"dwa({x}) - (2 + x) ";
  22.             return 2 + x;
  23.         }
  24.  
  25.         static void Main()
  26.         {
  27.             Funkcje ff = new Funkcje();
  28.             ff.fcja += x => x;
  29.             Console.WriteLine($"{ff.fcja(7)}");
  30.             ff.fcja += jeden;
  31.             Console.WriteLine($"{ff.fcja(5)}");
  32.             ff.fcja += dwa;
  33.             Console.WriteLine($"{ff.fcja(3)}");
  34.             ff.fcja -= jeden;
  35.             Console.WriteLine($"{ff.fcja(1)}");
  36.             Console.WriteLine(msg);
  37.             Console.ReadKey();
  38.         }
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement