double d1 = double.Nan;
double d2 = double.Nan;
Console.WriteLine(d1 == d2);
Console.WriteLine(d1.Equals(d2));上述代码第一行输出False
第二行输出True高手们有什么不同的解释?
double d2 = double.Nan;
Console.WriteLine(d1 == d2);
Console.WriteLine(d1.Equals(d2));上述代码第一行输出False
第二行输出True高手们有什么不同的解释?
解决方案 »
- 求大神帮助,用HttpListener,HttpListenerRequest,HttpListenerResponse写个http服务器实例,不要百度的那些,
- c#新手求助~串口通信
- 求助C#往Excel的Cell里插图片的问题
- 用longraw格式存在oracle的数据怎样在c#中显示出来
- 100分求网站数据经上级管理员审核的问题,
- 发现C#中的 “^”符号大家知道什么用途不,它在JAVA 和和C++中表示多少次方,但在C#中却不一样
- 菜鸟求助,如何获取数据库字段类型为float的值,等到晚上11点解决了马上给分
- 我想问一个XML的问题,需要比较了解的回答一下?
- 不知要学Winform还是WPF…
- string.Trim()的问题
- ListBox如何删除选中的那一项?
- 怎样使TextBox输入值后的值自动为空
d1 = 100;
d2 = 100;
的话,那么输出都是True
Console.WriteLine(double.NaN == double.NaN);
也会输出False
此常数的值是零被零除所得到的结果。
当运算结果未定义时返回此常数。
使用 IsNaN 确定值是否为非数字。不可能通过将某个值与另一个等于 NaN 的值进行比较来确定该值是否不是数字。看来就是CLR的约定
Dim zero As Double = 0' This condition will return false.
If (0 / zero) = Double.NaN Then
Console.WriteLine("0 / 0 can be tested with Double.NaN.")
Else
Console.WriteLine("0 / 0 cannot be tested with Double.NaN; use Double.IsNan() instead.")
End If
C#
Double zero = 0;// This condition will return false.
if ((0 / zero) == Double.NaN)
{
Console.WriteLine("0 / 0 can be tested with Double.NaN.");
}
else
{
Console.WriteLine("0 / 0 cannot be tested with Double.NaN; use Double.IsNan() instead.");
}
C++
Double zero = 0;// This condition will return false.
if ( (0 / zero) == Double::NaN )
{
Console::WriteLine( "0 / 0 can be tested with Double::NaN." );
}
else
{
Console::WriteLine( "0 / 0 cannot be tested with Double::NaN; use Double::IsNan() instead." );
}
J#
Double zero = new Double(0);// This condition will return false.
if (0 / zero.doubleValue() == Double.NaN) {
Console.WriteLine("0 / 0 can be tested with Double.NaN.");
}
else {
Console.WriteLine(
"0 / 0 cannot be tested with Double.NaN; "
+ "use Double.IsNan() instead.");
}
以上都会输出
0 / 0 cannot be tested with Double.NaN; use Double.IsNan() instead.