fork(1) download
  1. // http://w...content-available-to-author-only...t.com/Articles/11657/Understanding-Delegates-in-C
  2. using System;
  3. delegate void Delegate_Multicast(int x,int y);
  4. class Class2
  5. {
  6. static void Method1(int x,int y)
  7. {
  8. Console.WriteLine ("You're in Method 1");
  9. }
  10.  
  11. static void Method2(int x,int y)
  12. {
  13. Console.WriteLine ("You're in Method 2");
  14. }
  15.  
  16. public static void Main(string[] args)
  17. {
  18. Delegate_Multicast func = new Delegate_Multicast(Method1);
  19. func += new Delegate_Multicast(Method2);
  20. func(1,2); // Method1 and Method2 are called
  21. func -= new Delegate_Multicast(Method1);
  22. func(2,3); // Only Method2 is called
  23. }
  24. }
Success #stdin #stdout 0.02s 33752KB
stdin
Standard input is empty
stdout
You're in Method 1
You're in Method 2
You're in Method 2