static void Main(string[] args) { MyMath math = new MyMath(); double[] res = new double[5]; MyMath.Operation operation = MyMath.Add; res[0] = math.DoMath(14, 15, operation); operation = MyMath.Subtract; res[1] = math.DoMath(14, 15, operation); operation = MyMath.Multiply; res[2] = math.DoMath(14, 15, operation); operation = MyMath.Divide; res[3] = math.DoMath(14, 15, operation); operation = MyMath.Divide; res[4] = math.DoMath(14, 15, operation); Console.WriteLine(math.MathAdd(2, 3)); IntArray Arr = new IntArray(4, 4); Arr.OverRange += new IntArray.OverRangeHandler(DisplayMessage); double sum = Arr.GetSum(); Console.ReadKey(); }
/// <summary> /// manage the application loop /// </summary> static void ManageApplicationLoop() { bool running = true; while (running) { MathOperation operation; double operand1, operand2; Dictionary <MyMath.Operation, MathOperation> operationsDictionary = new Dictionary <MyMath.Operation, MathOperation>(); //need a flipped dictionary to handle unary operations Dictionary <MathOperation, MyMath.Operation> flippedOperationsDictionary = new Dictionary <MathOperation, MyMath.Operation>(); operationsDictionary = SetupOperations(); //from https://stackoverflow.com/questions/22595655/how-to-do-a-dictionary-reverse-lookup flippedOperationsDictionary = operationsDictionary.ToDictionary(x => x.Value, x => x.Key); operation = DisplayGetOperation(operationsDictionary); MyMath.Operation operationEnum = flippedOperationsDictionary[operation]; switch (operationEnum) { case MyMath.Operation.ADD: operand1 = ValidateOperand(1); operand2 = ValidateOperand(2); DisplayCalculation(operation, operand1, operand2); break; case MyMath.Operation.SUBTRACT: operand1 = ValidateOperand(1); operand2 = ValidateOperand(2); DisplayCalculation(operation, operand1, operand2); break; case MyMath.Operation.MULTIPLY: operand1 = ValidateOperand(1); operand2 = ValidateOperand(2); DisplayCalculation(operation, operand1, operand2); break; case MyMath.Operation.DIVIDE: operand1 = ValidateOperand(1); //divide by zero check operand2 = DivideByZeroCheck(2); DisplayCalculation(operation, operand1, operand2); break; case MyMath.Operation.EXPONENT: operand1 = ValidateOperand(1); operand2 = ValidateOperand(2); DisplayCalculation(operation, operand1, operand2); break; case MyMath.Operation.FACTORIAL: operand1 = ValidateOperand(1); DisplayCalculation(operation, operand1); break; case MyMath.Operation.ABS: operand1 = ValidateOperand(1); DisplayCalculation(operation, operand1); break; case MyMath.Operation.MODULO: operand1 = ValidateOperand(1); operand2 = ValidateOperand(2); DisplayCalculation(operation, operand1, operand2); break; case MyMath.Operation.NTHROOT: operand1 = ValidateOperand(1); operand2 = ValidateOperand(2); DisplayCalculation(operation, operand1, operand2); break; } running = ContinueOrExit(); } }