Why does the following code snippet returns 1:
double i = double.NaN;
double? i2 = null;
i.CompareTo(i2);
From my point of view it makes no sense. An Exception would be more appropriate.
What do you think was the reasoning behind the decision.
From the documentation on CompareTo:
The value parameter must be null or an instance of Double; otherwise, an exception is thrown. Any instance of Double, regardless of its value, is considered greater than null.
The value parameter in your example is null. NaN is therefore considered greater than null which is why CompareTo correctly returns 1.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With