SortedList默认是按按键名排序的,但有时候向让它按原来新增Item的顺序排序,怎么办?

解决方案 »

  1.   

    实现IComparer接口,返回-1就可以了。例如:
    public class noSort:IComparer
    {
       public int Compare(object x, object y)
       {
         return -1;
       }
    }SortedList mySD = new SortedList(new noSort()) ->这样就不会排序了
      

  2.   

    要实现IComparer接口
    如:
    SortedList sl=new SortedList(new ReverseComparer());class ReverseComparer:IComparer{
     public int Compare(object x,object y){
       DateTime l=(DateTime)x;
       return -(l.CompareTo(y));
     }
    }