public static OperationToDo GiveMeOperation(Operations operationType) { OperationToDo operationDone = null; switch (operationType) { case Operations.add: operationDone += Program.add; break; case Operations.sub: operationDone += Program.subtract; break; case Operations.mul: operationDone += Program.multiply; break; } return(operationDone); }
public static void Main(string[] args) { Console.WriteLine("Enter 2 numbers using format <number><space><number>:"); int[] numbers = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray(); Console.WriteLine("Enter operation to perform on numbers:"); Operations operation = (Operations)Enum.Parse(typeof(Operations), Console.ReadLine()); OperationToDo operationDone = OperationFactory.GiveMeOperation(operation); //Below switch replaced by call to factory //switch (operation) //{ // case Operations.add: operationDone += add; break; // case Operations.sub: operationDone += subtract; break; // case Operations.mul: operationDone += multiply; break; //} Console.WriteLine("Operation result is: " + operationDone(numbers[0], numbers[1])); }//main method