This is part of the code of a calculator that works on command line. It works fine and the math is correct but it's a little redundant:
switch(Operator)
{
case "+": result = num1 + num2;
printResult();
break;
case "-" : result = num1 - num2;
printResult();
break;
case "*":
result = num1 * num2;
printResult();
break;
case "/":
result = num1 / num2;
printResult();
break;
case "^":
result = Math.Pow(num1, num2);
printResult();
break;
case "root":
result = Math.Pow(num1, (1/num2));
Console.WriteLine("Root degree " + num2 + " of " + num1 + " is " + result);
break;
default:
Console.WriteLine("Invalid operator.");
break;
}//END SWITCH
Is there a way to avoid this redundant code like
result = num1 Operator num2;
or
for char o = Operator
result = num1 Operator num2;
Even just for the + - / * operations ?