Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2015
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.78 KB | None | 0 0
  1. using System;
  2.                    
  3. public class Program
  4. {
  5.     public static void Main()
  6.     {
  7.         var conn = new Conn();
  8.         var work = new Work(conn);
  9.         conn.Raise();
  10.     }
  11. }
  12.  
  13. public class Conn
  14. {
  15.     public Conn()
  16.     {
  17.         UserEvent += eventWorker;
  18.     }
  19.    
  20.     private void eventWorker()
  21.     {
  22.         Console.WriteLine("1");
  23.     }  
  24.    
  25.     private int age;
  26.     private string name;
  27.    
  28.     public delegate void UI ();
  29.     public event UI UserEvent;
  30.    
  31.     public void Raise()
  32.     {
  33.         if (UserEvent != null)
  34.             UserEvent();
  35.     }
  36. }
  37.  
  38. public class Work
  39. {
  40.     private Conn _conn;
  41.     public Work(Conn conn)
  42.     {
  43.         _conn = conn;
  44.         MajorWork();
  45.     }
  46.     private void MajorWork()
  47.     {
  48.         _conn.UserEvent += eventWorker;
  49.     }
  50.  
  51.     private void eventWorker()
  52.     {
  53.         Console.WriteLine("2");
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement