Advertisement
patryk

[PW] Laboratoria 3

Mar 16th, 2016
355
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.99 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.  
  8. /***    PROGRAMOWANE WIZUALNE - LABORATORIA 3   (16.03.2016)
  9.  *
  10.  *  Omawiano: Delegaty, Eventy, Wyrażenia Lambda
  11.  *  Na przyszłych: Typy Anonimowe
  12.  */
  13.  
  14. /*
  15.  *
  16.  *  int i = 5;
  17.  *  ... lamb [&i] (int a, int b)->{i = a*b*i; return i};
  18.  *  i += lamb (a, b, i); ????????
  19.  */
  20.  
  21. namespace ConsoleApplication1
  22. {
  23.  
  24.     class Małżonek
  25.     {
  26.         public Małżonek()
  27.         {
  28.             Console.WriteLine("MÓJ CI ON!");
  29.         }
  30.  
  31.         public void NasłuchujęDodOceny(double i)
  32.         {
  33.             switch ((int) i)
  34.             {
  35.                 case 2:
  36.                 Console.Write("Źle się uczysz, masz ");
  37.                 break;
  38.  
  39.                 case 5:
  40.                 Console.Write("Pięknie sobie radzisz, to pewnie zasługa R.W. dostałeś ");
  41.                 break;
  42.  
  43.                 default:
  44.                 Console.Write("Da się lepiej, masz ");
  45.                 break;
  46.             }
  47.             Console.WriteLine(i);
  48.         }
  49.     }
  50.  
  51.     class Student
  52.     {
  53.         private DelegatDodOceny delegatDodOceny;
  54.         public List<double> Oceny = new List<double>();
  55.        
  56.         public event DelegatDodOceny MójEvent
  57.         {
  58.             add
  59.             {
  60.                 this.delegatDodOceny += value;
  61.             }
  62.  
  63.             remove
  64.             {
  65.                 this.delegatDodOceny -= value;
  66.             }
  67.         }
  68.         public String Imie
  69.         {
  70.             set;
  71.             get;
  72.         }
  73.         public String Nazwisko
  74.         {
  75.             set;
  76.             get;
  77.         }
  78.         public String Indeks
  79.         {
  80.             set;
  81.             get;
  82.         }
  83.         public Małżonek M
  84.         {
  85.             set;
  86.             get;
  87.         }
  88.  
  89.  
  90.         //---------- METHODS ------------
  91.  
  92.         public Student (String imie, String nazwisko, String indeks)
  93.         {
  94.             this.Imie = imie;
  95.             this.Nazwisko = nazwisko;
  96.             this.Indeks = indeks;
  97.         }
  98.  
  99.         public void DodajOcenę (double ocena)
  100.         {
  101.             this.Oceny.Add(ocena);
  102.             this.delegatDodOceny(ocena);
  103.         }
  104.  
  105.         public void Ślub(Małżonek m)
  106.         {
  107.             this.M = m;
  108.             this.MójEvent += this.M.NasłuchujęDodOceny;
  109.         }
  110.  
  111.         public void przedstawSie()
  112.         {
  113.             String format = this.Imie + " " + this.Nazwisko + " " + this.Indeks + " ";
  114.             Console.WriteLine(format);
  115.         }
  116.     }
  117.  
  118.  
  119.     public delegate void DelegatDodOceny (double a);
  120.     public delegate int Delegat2(int x, int y);
  121.  
  122.  
  123.     class Program
  124.     {
  125.         static void Main(string[] args)
  126.         {
  127.             Student s = new Student("Patryk", "Gliszczyński", "117288");
  128.             s.Ślub(new Małżonek());
  129.             s.DodajOcenę(5.0);
  130.             s.DodajOcenę(2.0);
  131.  
  132.             Delegat2 l = ((int x, int y) => (x * y));
  133.         }
  134.     }
  135. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement