Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- return new RelayCommand(p => MessageBox.Show("It worked."));
- public RelayCommand(Action<object> execute, Predicate<object> canExecute)
- {
- if (execute == null)
- throw new ArgumentNullException("execute");
- _execute = execute;
- _canExecute = canExecute;
- }
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace TestLambda24
- {
- class Program
- {
- static void Main(string[] args)
- {
- int[] numbers = { 6, 3, 7, 4, 8 };
- //Console.WriteLine("The addition result is {0}.", Tools.ProcessNumbers(p => Tools.AddNumbers, numbers));
- Console.WriteLine("The addition result is {0}.", Tools.ProcessNumbers(Tools.AddNumbers, numbers));
- //Console.WriteLine("The multiplication result is {0}.", Tools.ProcessNumbers(p => Tools.MultiplyNumbers, numbers));
- Console.WriteLine("The multiplication result is {0}.", Tools.ProcessNumbers(Tools.MultiplyNumbers, numbers));
- Console.ReadLine();
- }
- }
- class Tools
- {
- public static int ProcessNumbers(Func<int[], int> theMethod, int[] integers)
- {
- return theMethod(integers);
- }
- public static int AddNumbers(int[] numbers)
- {
- int result = 0;
- foreach (int i in numbers)
- {
- result += i;
- }
- return result;
- }
- public static int MultiplyNumbers(int[] numbers)
- {
- int result = 1;
- foreach (int i in numbers)
- {
- result *= i;
- }
- return result;
- }
- }
- }
- static void Main(string[] args)
- {
- int[] numbers = { 6, 3, 7, 4, 8 };
- Console.WriteLine("The addition result is {0}.",
- Tools.ProcessNumbers(p => Tools.AddNumbers(p), numbers));
- Console.WriteLine("The multiplication result is {0}.",
- Tools.ProcessNumbers(p => Tools.MultiplyNumbers(p), numbers));
- Console.ReadLine();
- }
Add Comment
Please, Sign In to add comment