1、下载MathParser.org-mXparser dll包
dotnet add package MathParser.org-mXparser --version 5.2.0
2、引入dll
using org.mariuszgromada.math.mxparser;
3、测试demo
static void Main(string[] args) { bool isCallSuccessful = License.iConfirmNonCommercialUse("Johnny"); Constant x = new Constant("x", 10); Constant y = new Constant("y", 1); Expression expression = new Expression("x+y", x, y); Console.WriteLine(x.getConstantName() + " = " + x.getConstantValue()); Console.WriteLine(y.getConstantName() + " = " + y.getConstantValue()); Console.WriteLine("Res: " + expression.getExpressionString() + " = " + expression.calculate()); Console.ReadKey( ); }
4、输出记录
x = 10 y = 1 Res: x+y = 11
可以开心的计算用户自己设置的表达式了。。。
标签:Console,C#,mXparser,WriteLine,MathParser,org,Constant From: https://www.cnblogs.com/JohnnyLei/p/17094483.html