SortedList类默认是升序的,要改成降序要怎么改呢?
通过实现IComparer:
public class ReverserSort : IComparer<string>
{
private bool Asc=true;
int IComparer<KeyValueItem>.Compare(string x, string y)
{
if (Asc)
return string.Compare(x, y);
else
return string.Compare(y, x);
通过实现IComparer:
public class ReverserSort : IComparer<string>
{
private bool Asc=true;
int IComparer<KeyValueItem>.Compare(string x, string y)
{
if (Asc)
return string.Compare(x, y);
else
return string.Compare(y, x);
}
public bool bAsc
{
set { Asc = value; }
}
}
其中string类型也可以是其他类型
ReverserSort ms = new ReverserSort();
ms.Asc = false;
SortedList li = new SortedList();
Array.Sort(li, ms);
-----------------------------------------
去除SortedList的自动排序功能
【推广】
免费学中医,健康全家人
原文地址:https://www.cnblogs.com/fx2008/p/2304668.html