string stringValue = "1+2+3";
How can I convert the above string value with operators, "1+2+3", so that it can be assigned to the intvalue as shown below in C#.
int intValue = 1+2+3;
i.e intValue = 6;
string stringValue = "1+2+3";
How can I convert the above string value with operators, "1+2+3", so that it can be assigned to the intvalue as shown below in C#.
int intValue = 1+2+3;
i.e intValue = 6;
You need to compile on the fly. See for example Evaluate C# Code or Flee.
Use DataTable.Compute (http://msdn.microsoft.com/en-us/library/system.data.datatable.compute.aspx)
var result = new DataTable().Compute("2-3/4*12", null);
ANd this has been asked so many times before.
I have used this library in many projects: C# calculation engine
It's very simple to use:
var ce = new CalcEngine();
double result = (double)ce.Evaluate("1+2+3");