Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Collections.Generic;
- namespace lab8
- {
- class MainClass
- {
- delegate void Print();
- delegate string Merge(int a, string b, string c);
- delegate void Merge2(Print x, string d);
- public class MyEvent
- {
- public delegate void Get();
- public event Get zzz;
- public void Go()
- {
- if(zzz != null)
- zzz();
- }
- }
- public class Person : IComparable<Person>
- {
- protected int age;
- protected string name, surname;
- public int CompareTo(Person other)
- {
- return other.age.CompareTo(this.age);
- }
- public Person(int age, string name, string surname)
- {
- try
- {
- if (age < 0) throw new Exception();
- this.age = age;
- this.name = name;
- this.surname = surname;
- }
- catch
- {
- Console.WriteLine("Error : Age < 0");
- //Environment.Exit(0);
- }
- }
- public virtual void Print()
- {
- Merge Foo = (x, y, z) => ("Age = " + x + "\nName = " + y + "\nSurname = " + z);
- string ans = Foo(age, name, surname);
- Console.WriteLine(ans);
- }
- }
- public class Student : Person
- {
- protected string university;
- public Student(int age, string name, string surname, string university)
- : base(age, name, surname)
- {
- this.university = university;
- }
- readonly Merge2 Foo = delegate (Print func, string x)
- {
- func();
- Console.WriteLine("University = " + x + "\n");
- };
- public override void Print()
- {
- Foo(base.Print, university);
- }
- }
- public static void Main(string[] args)
- {
- List<Person> arr = new List<Person>();
- arr.Add(new Person(-1, "qqq", "fdfd"));
- arr.Add(new Person(132, "pppp", "fdjf"));
- arr.Add(new Student(1333, "fjkd", "qqq", "222"));
- MyEvent x = new MyEvent();
- foreach(var item in arr)
- {
- x.zzz += item.Print;
- }
- x.Go();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement