1

In C#, Single.Equals

Returns a value indicating whether two instances of Single represent the same value.

While Single's Equality operator (==)

The equality operator == returns true if its operands are equal, false otherwise.

(emphasis mine).

One notable difference between these comparison methods involves NaN:

float.NaN.Equals(float.NaN) => true
float.NaN == float.NaN => false

I understand why operator== is false between NaNs (answer here), but why is Equals different? Are there other values for which Equals provides a different result than operator==?

mekin
  • 99
  • 4

0 Answers0