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

posted on 2009-10-13 11:26  alon  阅读(655)  评论(0编辑  收藏  举报

导航