Solutions provided by
Mehdi Gholam and
CIDev is quite good but i would like to show you some alternative and simple code that would not require any 3rd party library! Let's see:
class Program
{
const string expressionColumn = "expression";
public static void Main(string[] args)
{
Console.WriteLine(Evaluate("5+10+5+22+22.5-10"));
}
private static double Evaluate(string expression)
{
DataTable table = new DataTable();
table.Columns.Add(expressionColumn, typeof(string), expression);
DataRow row = table.NewRow();
table.Rows.Add(row);
return double.Parse((string)row[expressionColumn]);
}
}
Cheers!
Shuvro