Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Data;
- namespace FancyCalc
- {
- public class FancyCalcEnguine
- {
- public double Add(double a, double b)
- {
- return a + b;
- }
- public double Subtract(double a, double b)
- {
- return a - b;
- }
- public double Multiply(double a, double b)
- {
- return a * b;
- }
- public double Divide(double a, double b)
- {
- if (b == 0) return a;
- return a / b;
- }
- //generic calc method. usage: "10 + 20" => result 30
- public double Culculate(string expression)
- {
- if (expression == null) throw new ArgumentNullException();
- int myInt;
- DataTable dt = new DataTable();
- var v = dt.Compute(expression, "");
- bool IsNumerical = int.TryParse(v.ToString(), out myInt);
- if (IsNumerical == false)
- {
- return 0;
- }
- double c = Convert.ToDouble(v.ToString());
- return c;
- }
- }
- }
Add Comment
Please, Sign In to add comment