Advertisement
Guest User

Events - Hello Goodbye

a guest
Jul 25th, 2014
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.21 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace Events2
  7. {
  8.  
  9.     delegate void YouSayYes();
  10.     delegate void YouSayStop();
  11.  
  12.     class John{
  13.  
  14.         public event YouSayYes yousayyes;
  15.         public event YouSayStop yousaystop;
  16.  
  17.  
  18.         public void Sing()
  19.         {
  20.             Console.WriteLine("I say yes");
  21.             if (yousayyes != null) yousayyes();
  22.  
  23.             Console.WriteLine("I say stop");
  24.             if (yousayyes != null) yousaystop();
  25.  
  26.        
  27.        
  28.         }
  29.  
  30.  
  31.  
  32.  
  33.    
  34.    
  35.     }
  36.  
  37.  
  38.     class George{
  39.  
  40.         public void ISayNo(){
  41.  
  42.             Console.WriteLine("I say no !!");
  43.         }
  44.  
  45.  
  46.         public void ISayGo()
  47.         {
  48.  
  49.             Console.WriteLine("I say Go Go gooooooooo !!");
  50.         }
  51.  
  52.  
  53.     }
  54.  
  55.  
  56.     class Program
  57.     {
  58.         static void Main(string[] args)
  59.         {
  60.  
  61.              George georgie = new George();
  62.  
  63.              John Lennon = new John();
  64.  
  65.  
  66.             Lennon.yousayyes +=new YouSayYes(  georgie.ISayNo    );
  67.             Lennon.yousaystop += new YouSayStop(  georgie.ISayGo   );
  68.  
  69.             Lennon.Sing();
  70.  
  71.  
  72.             Console.ReadKey();
  73.  
  74.  
  75.         }
  76.     }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement