When is Double's == operator invoked?

前端 未结 3 1338
执笔经年
执笔经年 2021-02-18 14:22

It all started with a trick question that someone posed to me.. (It\'s mentioned in the book - C# in a nutshell) Here\'s the gist of it.

Double a = Double.NaN;
C         


        
3条回答
  •  广开言路
    2021-02-18 15:00

    From msdn : http://msdn.microsoft.com/en-us/library/ya2zha7s.aspx

    If two Double.NaN values are tested for equality by calling the Equals method, the method returns true. However, if two NaN values are tested for equality by using the equality operator, the operator returns false. When you want to determine whether the value of a Double is not a number (NaN), an alternative is to call the IsNaN method.

提交回复
热议问题