3
可能重複:
C# eval equivalent?
How can I evaluate a C# expression dynamically?C#.NET 4.0的表達EVAL
如何評估一個有效的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) */
希望你有這個想法。
謝謝。
和http://stackoverflow.com/questions/1024070/c-eval-support – 2010-11-12 07:38:07