Making a calculation according to the BODMAS in C# [closed]

不羁的心 提交于 2019-12-13 22:50:23

问题


Guys I have a calculation that is built by a user in a text box. In short, he defines the format he wants and the values are passed on later(after some database queries).

eg. (X + Y) * 55

or he may also bulid as

(X - 100) * 100

Is there any way of computing this with c# ?

NOTE : X and Y are retrieved from a database.


回答1:


have a look at http://NCalc.Codeplex.com

its an easy to use and extensibile calculation engine for C#

Example of how to use is :

 Expression e = new Expression("2 + 3 * 5");
  Debug.Assert(17 == e.Evaluate());



回答2:


Without doing it for you, you could either look here for information about using Lua in C#.

For another way you could create a system like this which creates an actual calculator. You could extend it by adding ( and ) buttons to compute those first.



来源:https://stackoverflow.com/questions/20210926/making-a-calculation-according-to-the-bodmas-in-c-sharp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!