【发布时间】:2011-05-08 22:20:14
【问题描述】:
可能的重复:
C# eval equivalent?
How can I evaluate a C# expression dynamically?
如何评估有效的 C# 代码并在已编译的程序中(动态)获得结果? 我知道这不是很清楚,我会尝试用代码 sn-p 来说明:
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) */
希望你明白了。
谢谢。
【问题讨论】:
标签: c# linq parsing function eval