Fastest way to sort an array in descending order

前端 未结 4 1259
春和景丽
春和景丽 2020-12-15 20:51

Why is the following code

Array.Sort(values);
Array.Reverse(values);

much faster at sorting an array in descending order compared to

<
4条回答
  •  误落风尘
    2020-12-15 21:16

    Delegates.

    The call to the delegate is much slower than the default call to IComparable.CompareTo

    Update:

    If you want the same (or close) speed, implement the IComparer interface and pass that to the sort method.

    http://msdn.microsoft.com/en-us/library/bzw8611x

提交回复
热议问题