Better way to sort array in descending order

后端 未结 7 2192
伪装坚强ぢ
伪装坚强ぢ 2020-12-01 09:54

I have a array of int which I have to sort by descending.

Since I did not find any method to sort the array in descending order.Currently I am sorting the array in

7条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-01 10:43

    Use LINQ OrderByDescending method. It returns IOrderedIEnumerable, which you can convert back to Array if you need so. Generally, List<>s are more functional then Arrays.

    array = array.OrderByDescending(c => c).ToArray();
    

提交回复
热议问题