c#ArrayList 对象集合 按某字段(属性)排序

主程序代码

newsCompare newsCompare = new ItemManage.newsCompare();

                    newsList.Sort(newsCompare);

自定义类代码(按照CREATEDATE属性排序)

class newsCompare : IComparer
    {
        int System.Collections.IComparer.Compare(object x, object y)
        {
            TJZB_GDNEWS model1 = new TJZB_GDNEWS();
            TJZB_GDNEWS newsX = (TJZB_GDNEWS)x;
            TJZB_GDNEWS newsY = (TJZB_GDNEWS)y;
            if (newsX.CREATEDATE > newsY.CREATEDATE)
                return -1;
            if (newsX.CREATEDATE < newsY.CREATEDATE)
                return 1;
            return 0;
        }
    }

 

posted @ 2015-11-05 11:36  Jydu  阅读(5937)  评论(0编辑  收藏  举报