7
Reply

Dun understand why Add when it should be Substrate

Tangara G

Tangara G

Nov 8 2016 10:02 PM
223
Dear experts,
 
I have this multi-cast delegate which I am having problem understand:
 
  1. delegate void M(int x, int y);  
  2.   
  3. public class Oper  
  4. {  
  5.   public static void Add(int x, int y)  
  6.   {  
  7.    Console.WriteLine("{0} + {1} = {2}", x, y, x+y);  
  8.  }  
  9.   
  10.  public static void Sub(int x, int y)  
  11. {  
  12. Console.WriteLine("{0} + {1} = {2}", x, y, x+y);  
  13. }  
  14.   
  15. public class CSharpApp  
  16. {  
  17.  static void Main()  
  18. {  
  19. M del = new M(Oper.Add);  
  20. del += new M(Oper.Sub);  
  21. del(6,4);  
  22.   
  23. del -= new M(Oper.Sub);  
  24. del(2,8);  
  25. }  
  26. }  
I would like to know why the output for del(2,8) is 10 instead of 2 - 8 which is -6.  

Answers (7)