コード例 #1
0
 public float?Calculate(string expression)
 {
     try
     {
         var postfix = new InflixToPostfixService().ToPostfix(expression);
         return(new PostfixEvaluatorService().Evaluate(postfix));
     }
     catch (DivideByZeroException)
     {
         Console.WriteLine("Invalid expression");
         return(null);
     }
     catch (Exception)
     {
         Console.WriteLine("Oops, something went wrong. Apologies, your expression string is not supported yet.");
         return(null);
     }
 }
コード例 #2
0
 /// <summary>
 /// This should really be injected through DI Container
 /// </summary>
 public CalculatorService()
 {
     inflixToPostfixService  = new InflixToPostfixService();
     postfixEvaluatorService = new PostfixEvaluatorService();
 }