可能是重复问题:
C# eval等效功能?
如何动态评估C#表达式?
如何在编译的程序中评估有效的C#代码并获取结果(动态)? 我知道这不是很清楚,我会尝试用代码片段来展示:
Visual C# 2010。
double x = 3.0;//this is function argument, we'll take 3
string str = "Math.Pow(x,2)+2*x+4";//value with written function in C#,equals: x^2+2x+4
double y = eval(str);
/* this is the idea! something like JS.I want to make string parsed into parameter,i.e
y=19 - this is what double y should became after eval(str) */
希望您已经理解了这个概念。 谢谢。