static void Main(string[] args) { Console.WriteLine("Enter an array of integers:"); string ints_string = Console.ReadLine(); string[] ints_string_array = ints_string.Split(new string[] { " ", ",", ", " }, StringSplitOptions.RemoveEmptyEntries); var ints_array = new int[ints_string_array.Length]; for (var i = 0; i < ints_string_array.Length; i++) { ints_array[i] = Convert.ToInt32(ints_string_array[i]); } Console.WriteLine("Enter 'evens' or 'odds':"); string filter = Console.ReadLine().ToLower(); Console.WriteLine("Enter 'sum', 'max' or 'avg':"); string action = Console.ReadLine().ToLower(); MathClass.Del_1 del_filter = null; if (filter == "evens") { del_filter = MathClass.Evens; } else if (filter == "odds") { del_filter = MathClass.Odds; } else { Console.WriteLine("You entered invalid filter. It should be either 'evens' or 'odds'." + "Given array was not filtered."); } MathClass.Del_2 del_action = null; if (action == "sum") { del_action = MathClass.Sum_; } else if (action == "max") { del_action = MathClass.Max_; } else if (action == "avg") { del_action = MathClass.Avg_; } else { Console.WriteLine("You entered invalid action. It should be either 'sum', 'max' or 'avg'."); } Output(del_filter, del_action, ints_array); Console.ReadKey(); }
public static void Output(MathClass.Del_1 del_1, MathClass.Del_2 del_2, int[] arr) { int?result = del_2?.Invoke(del_1, arr); Console.WriteLine(result); }