This stackoverflow question raised an interesting question about sorting double arrays with NaN values. The OP posted the following code:
static void Main(st
It's a bug fix. The feedback report with the bug details is here. Microsoft's response to the bug report:
Note that this bug affects the following:
- Array.Sort(), where the array contains Double.NaN
- Array.Sort(), where the array contains Single.NaN
- any callers of above, for example on List.Sort(), where list contains Double.NaN
This bug will be fixed in the next major version of the runtime; until then you can work around this by using a custom IComparer that does the correct sorting. As mentioned in the workaround comments, don't use Comparer.Default, because this is special-cased with a shortcut sort routine that doesn't handle NaN correctly. Instead, you can provide your own comparer that provides an equivalent comparision, but won't be special-cased.