automatically calculate string mathematical expressing in C#

前端 未结 1 341
眼角桃花
眼角桃花 2021-01-29 13:53

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 v

相关标签:
1条回答
  • 2021-01-29 14:27

    There isn't such a thing in .net itself, but if you have just primary operations you can parse input string and find related values, for this you can use shunting yard algorithm or reverse polish notation, but also you can use NCalc for more complicated scenarios.

    0 讨论(0)
提交回复
热议问题