-2

I have a C# string which is representation of a mathematical expression, something like this:

A = (B*0.25)+(D*0.25)+(1-W)

how can I calculate value of A? should I manually parse all characters, then perform my calculation? Although it is possible but I think it would be time-consuming to write such a code, is there any way that C# can understand this string and calculate value of A (of course I would declare A, B, D & W as variables

thanks

4

1 回答 1

3

.net 本身没有这样的东西,但是如果您只有主要操作,您可以解析输入字符串并找到相关值,为此您可以使用分流场算法或反向波兰表示法,但您也可以使用NCalc获得更多信息复杂的场景。

于 2012-04-06T11:45:28.760 回答