Advertisement
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;
- delegate double deleg(double num); // делагат
- class Event
- {
- double q;
- public Event(double num)
- {
- q = num;
- }
- public event deleg UserEvent;
- public void MyEvent(double q)
- {
- UserEvent(q);
- }
- }
- class Delegate
- {
- double a;
- public Delegate(double num)
- {
- a = num;
- }
- public double Double(double input)
- {
- return input * 2;
- }
- public double UserInfoHandler(double q)
- {
- Console.WriteLine("Событие {0} вызвано!", q);
- Console.WriteLine("Multiply by 2: {0}", Double (a));
- Console.WriteLine();
- return q;
- }
- }
- class Program
- {
- static void Main()
- {
- Delegate del = new Delegate(4.5);
- Event evt = new Event(1);
- deleg d1 = new deleg(del.Double);
- evt.UserEvent += del.UserInfoHandler;
- evt.MyEvent(1);
- deleg d2 = delegate (double input)
- {
- return input * input;
- };
- Console.WriteLine("Square: {0}", d2(5));
- Console.WriteLine();
- deleg d3 = s => s * s * s;
- Console.WriteLine("Cube: {0}", d3(5));
- Console.ReadKey();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement