public static double Calculate(string request) { string[] splitedRequest = request.Split(':'); string operation = splitedRequest[0]; double firstValue; double secondValue; bool f = double.TryParse(splitedRequest[1], out firstValue); bool s = double.TryParse(splitedRequest[2], out secondValue); if (!(f && s)) { throw new Exception("Invalid imput!"); } IMathService mathService = new MathService(); switch (operation) { case "+": return(mathService.Add(firstValue, secondValue)); case "-": return(mathService.Sub(firstValue, secondValue)); case "*": return(mathService.Mult(firstValue, secondValue)); case "/": return(mathService.Div(firstValue, secondValue)); default: throw new Exception("Invalid operation!"); } }
public static void Main(String[] args) { MathService.MathService ms = new MathService.MathService(); Console.WriteLine(ms.Add(1,2)); }
public static void Main(String[] args) { MathService.MathService ms = new MathService.MathService(); Console.WriteLine(ms.Add(1, 2)); }