SortedList Desc Order

前端 未结 4 658
闹比i
闹比i 2021-01-17 07:09

I am using SortedList to arrange arraylist records dynamically in sort order by datecolumn, but by default it is sorting in ascending

4条回答
  •  臣服心动
    2021-01-17 07:53

    Swapping y for x should do when comparing

    class DescComparer : IComparer
    {
        public int Compare(T x, T y)
        {
            if(x == null) return -1;
            if(y == null) return 1;
            return Comparer.Default.Compare(y, x);
        }
    }
    

    and then this

    var list = new SortedList(new DescComparer());
    

提交回复
热议问题