本文介绍了在C#中:表达式求值功能如Flash脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何评价表达。也许这样的:
How to evaluate expression. Maybe like:
int a=1;
int b=3;
int c=Eval("a+b");
或
int c=int.parse("1+3*(2+3)");
这似乎是愚蠢的我。是否有可能在C#?
This seems stupid to me. is it possible in c#?
推荐答案
您可以采取的代码,并使用CSharpCodeProvider写,其实您的代码编译成一个eval函数在内存中的程序集,然后执行该代码。
You can take code, and using the CSharpCodeProvider write an Eval function that actually compiles your code into an in-memory assembly and then executes that code.
请参阅本的。
这篇关于在C#中:表达式求值功能如Flash脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!