Evaluating string quot;3*(4+2)quot; yield int 18(评估字符串“3*(4+2)产量 int 18)
问题描述
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)","");
这篇关于评估字符串“3*(4+2)"产量 int 18的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!