我如何动态地评估C#中的数学表达式。 [英] How I do evaluate mathematical expression in C# dynamically.?

查看:63
本文介绍了我如何动态地评估C#中的数学表达式。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我将字符串值动态读入一个变量,如3 + 5 * 9(6-4)。但我的问题是如何在c#中评估这种类型的数学表达式。?



我尝试过的事情:



我在c#中尝试过EvaluateExpression()方法,但它不起作用。

when i read the string value dynamically into one variable like "3+5*9(6-4)". but my problem is how can i evaluate this type of mathematical expressions in c#.?

What I have tried:

I tried EvaluateExpression() method in c#, but it's not working.

推荐答案

见这里:重新访问表达式评估程序(100%托管.NET中的Eval函数) [ ^ ]


除了OriginalGriff解决方案,你还应该尝试

实现类似Excel的公式引擎 [ ^ ]

我用过在我以前的项目中,它运作良好。
In addition to OriginalGriff solution, you shall try
Implementing an Excel-like formula engine[^]
I used this in my previous project, it works good.


这篇关于我如何动态地评估C#中的数学表达式。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆