[转载]SortedList实现排序 Dictionary, SortedDictionary, SortedList 比较

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);

        }
        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