作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是新来的!我是 C# 新手。我的一位 friend 向我发起挑战,要求我创建科学计算器。我搜索并找到了一种简单的方法来实现它 - 使用 System.Data 库。例如,我们有这样的:
string math = "5 + 3 * 3";
string answer = new DataTable().Compute(math, null).ToString();
这对于基本表达式来说非常容易,但我似乎找不到一种方法让计算器能够计算 sin、cos 等。有人有想法吗?
PS:我英语不好,请原谅我
最佳答案
感谢 Mat J 告诉我有关 mXparser 的信息!我找到了一种无需更改大量代码即可计算的方法!
这是 mXparser:http://mathparser.org/
代码的变化如下:它是:
string math = "5 + 3 * 3";
string answer = new DataTable().Compute(math, null).ToString();
现在是:
string math = "5 + 3 * 3";
Expression e = new Expression(math);
math = e.calculate();
唯一的事情是它使用表达式而不是字符串,但它仍然工作得非常简单!
我要感谢大家的快速答复!你真的帮了我大忙!
关于c# - 如何在 C# 中使用 System.Data.Compute() 计算 sin,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42750507/
我是一名优秀的程序员,十分优秀!