Hi,
I have 2 type's of codes that use
datatable in order to evaluate
a string like "2+3/4" and return the result.
I'm looking for a way to modify them so i can evaluate a string
with variable's so i can read new data from the user in runtime, like "2+X/4"
when X is assigned with some number before.
first code type uses datatable.compute:
using (DataTable eval = new DataTable())
{
var result = eval.Compute("1+2*3/4", null);
Console.WriteLine("Result: {0} of Type: {1}", result, result.GetType().Name);
}
second code:
static double Evaluate(string expression) {
var loDataTable = new DataTable();
var loDataColumn = new DataColumn("Eval", typeof (double), expression);
loDataTable.Columns.Add(loDataColumn);
loDataTable.Rows.Add(0);
return (double) (loDataTable.Rows[0]["Eval"]);
}
doesnt matter to me which code to use.
I cant use third party projects like Ncalc,IT department doesnt allow it.