Is there a function the .NET framework that can evaluate a numeric expression contained in a string and return the result? F.e.:
string mystring = "3*(2+4)";
int result = EvaluateExpression(mystring);
Console.Writeln(result); // Outputs 18
Is there a standard framework function that you can replace my EvaluateExpression
method with?
If you want to evaluate a string expression use the below code snippet.
using System.Data;
DataTable dt = new DataTable();
var v = dt.Compute("3 * (2+4)","");