Guest User

Untitled

a guest
Jun 22nd, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. return new RelayCommand(p => MessageBox.Show("It worked."));
  2.  
  3. public RelayCommand(Action<object> execute, Predicate<object> canExecute)
  4. {
  5. if (execute == null)
  6. throw new ArgumentNullException("execute");
  7.  
  8. _execute = execute;
  9. _canExecute = canExecute;
  10. }
  11.  
  12. using System;
  13. using System.Collections.Generic;
  14. using System.Linq;
  15. using System.Text;
  16.  
  17. namespace TestLambda24
  18. {
  19. class Program
  20. {
  21. static void Main(string[] args)
  22. {
  23. int[] numbers = { 6, 3, 7, 4, 8 };
  24.  
  25. //Console.WriteLine("The addition result is {0}.", Tools.ProcessNumbers(p => Tools.AddNumbers, numbers));
  26. Console.WriteLine("The addition result is {0}.", Tools.ProcessNumbers(Tools.AddNumbers, numbers));
  27.  
  28. //Console.WriteLine("The multiplication result is {0}.", Tools.ProcessNumbers(p => Tools.MultiplyNumbers, numbers));
  29. Console.WriteLine("The multiplication result is {0}.", Tools.ProcessNumbers(Tools.MultiplyNumbers, numbers));
  30.  
  31. Console.ReadLine();
  32. }
  33. }
  34.  
  35. class Tools
  36. {
  37. public static int ProcessNumbers(Func<int[], int> theMethod, int[] integers)
  38. {
  39. return theMethod(integers);
  40. }
  41.  
  42. public static int AddNumbers(int[] numbers)
  43. {
  44. int result = 0;
  45. foreach (int i in numbers)
  46. {
  47. result += i;
  48. }
  49. return result;
  50. }
  51.  
  52. public static int MultiplyNumbers(int[] numbers)
  53. {
  54. int result = 1;
  55. foreach (int i in numbers)
  56. {
  57. result *= i;
  58. }
  59. return result;
  60. }
  61. }
  62.  
  63. }
  64.  
  65. static void Main(string[] args)
  66. {
  67. int[] numbers = { 6, 3, 7, 4, 8 };
  68.  
  69. Console.WriteLine("The addition result is {0}.",
  70. Tools.ProcessNumbers(p => Tools.AddNumbers(p), numbers));
  71.  
  72. Console.WriteLine("The multiplication result is {0}.",
  73. Tools.ProcessNumbers(p => Tools.MultiplyNumbers(p), numbers));
  74.  
  75. Console.ReadLine();
  76. }
Add Comment
Please, Sign In to add comment