Advertisement
Dennisaa

Del and Lamdba 01

Jan 8th, 2016
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.70 KB | None | 0 0
  1. public delegate void SomeCalc(int a, int b);
  2. Action<int, int> ActionAdd = (a,b) => Console.WriteLine(string.Format("Addition result in Action: {0}", a + b));
  3. Action<int, int> ActionMult = (a,b) => Console.WriteLine(string.Format("Multiply result in Action: {0}", a * b));
  4.  
  5.  
  6. void Main()
  7. {
  8.     var x = 5;
  9.     var y = 6;
  10.    
  11.     var delAdd = new SomeCalc(Add);
  12.     var delMultiply = new SomeCalc(Multiply);
  13.    
  14.     delAdd(x,y);
  15.     delMultiply(x,y);
  16.    
  17.     ActionAdd(x,y);
  18.     ActionMult(x,y);
  19.    
  20.    
  21.    
  22.    
  23. }
  24.  
  25. public void Add(int c, int d) {
  26.     Console.WriteLine(string.Format("Addition result: {0}", c + d));
  27. }
  28.  
  29. public void Multiply(int e, int f) {
  30.     Console.WriteLine(string.Format("Multiplication result: {0}", e * f));
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement