排序列表倒序 [英] SortedList Desc Order

查看:341
本文介绍了排序列表倒序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用排序列表来安排动态由datecolumn排序顺序ArrayList的记录,但默认情况下它是排序中升序顺序,然后我一直在试图说明为了得到订单,但没有能够得到它。

i am using SortedList to arrange arraylist records dynamically in sort order by datecolumn, but by default it is sorting in Asc Order, then i have been trying to get order in Desc Order but not able to get it.

推荐答案

有没有办法指导SortedList的做在下降顺序排序。你必须提供自己的Comparer这样

There is no way to instruct the SortedList to do sorting in descended order. You have to provide your own Comparer like this

    class DescendedDateComparer : IComparer<DateTime>
    {
        public int Compare(DateTime x, DateTime y)
        {
            // use the default comparer to do the original comparison for datetimes
            int ascendingResult = Comparer<DateTime>.Default.Compare(x, y);

            // turn the result around
            return 0 - ascendingResult;
        }
    }

    static void Main(string[] args)
    {
        SortedList<DateTime, string> test = new SortedList<DateTime, string>(new DescendedDateComparer());
    }

这篇关于排序列表倒序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆