问题描述
在尝试找到一个简单的C#数学计算器时,我已经找到一个。
对我来说是理想的,因为它不需要任何COM或其他第三方参考。
但是,我发现一个令人困惑的事情:
新的DataTable()。Compute(2-3 / 4 * 12,null)//工作正常,答案是-7;
new DataTable()。Compute(2/0,null)//工作但不正确,答案是8;
new DataTable()。Compute(100/0,null)//工作但不正确,答案是8;
new DataTable()。Compute(2.0 / 0,null)//按照估计的方式抛出System.DivideByZeroException。
所以我想问一下,第二行和第三行怎么了?计算方法是否处理/是另一种方式?
我已阅读:,但没有任何帮助。
这个问题的一部分已经被回答:
我们有一个应用程序,Windows 8.1将为1/0表达式打印无限远。在Windows 10上,它返回8。
它的数值不是8,但是不正确显示的Unicode字符(这应该是一个死8) / p>
While trying to find a simple C# math calculator, I have found one below.C# Math calculator
It is ideal for me since it does not need any COM or other third-party reference.However, I find out a confusing thing:
new DataTable().Compute("2-3/4*12", null) // Works fine, answer is -7;
new DataTable().Compute("2 / 0", null) // Works but not correct, answer is 8;
new DataTable().Compute("100 / 0", null) // Works but not correct, answer is 8;
new DataTable().Compute("2.0 / 0", null) // Throw System.DivideByZeroException as estimated.
So I would like to ask, what's wrong with the second and third lines? Is the compute method treat the "/" is another way?
I have read this: https://msdn.microsoft.com/en-us/library/system.data.datatable.compute.aspx, but nothing helpful.
Part of this question has already been answered:Why is infinity printed as "8" in the Windows 10 console?
We have an application that on Windows 8.1 will print "Infinity" for an expression such as "1 / 0". On Windows 10, it returns "8".
It's not a numeric value of 8, but an incorrectly displayed Unicode character (which should be a dead-8).
这篇关于关于C#DataTable.Compute()的语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!