axeefectushka

Untitled

Feb 15th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.20 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Data;
  7.  
  8. namespace FancyCalc
  9. {
  10.     public class FancyCalcEnguine
  11.     {
  12.  
  13.         public double Add(double a, double b)
  14.         {
  15.             return a + b;
  16.         }
  17.  
  18.  
  19.         public double Subtract(double a, double b)
  20.         {
  21.             return a - b;
  22.         }
  23.  
  24.         public double Multiply(double a, double b)
  25.         {
  26.             return a * b;
  27.         }
  28.         public double Divide(double a, double b)
  29.         {
  30.             if (b == 0) return a;
  31.             return a / b;
  32.         }
  33.         //generic calc method. usage: "10 + 20"  => result 30
  34.         public double Culculate(string expression)
  35.         {
  36.             if (expression == null) throw new ArgumentNullException();
  37.             int myInt;
  38.             DataTable dt = new DataTable();
  39.             var v = dt.Compute(expression, "");
  40.             bool IsNumerical = int.TryParse(v.ToString(), out myInt);
  41.             if (IsNumerical == false)
  42.             {
  43.                 return 0;
  44.             }
  45.             double c = Convert.ToDouble(v.ToString());
  46.             return c;
  47.         }
  48.     }
  49. }
Add Comment
Please, Sign In to add comment