泛型列表根据某个字段进行排序的用法


泛型列表根据某个字段进行排序的用法

        List<ZK.HIIS.Entities.SEARCH_ITEM_RESULT> lst = new List<ZK.HIIS.Entities.SEARCH_ITEM_RESULT>();
        ZK.HIIS.Entities.SEARCH_ITEM_RESULT RESULT1 = new ZK.HIIS.Entities.SEARCH_ITEM_RESULT();
        RESULT1.ORDER = 2;
        ZK.HIIS.Entities.SEARCH_ITEM_RESULT RESULT2 = new ZK.HIIS.Entities.SEARCH_ITEM_RESULT();
        RESULT2.ORDER = 0;
        ZK.HIIS.Entities.SEARCH_ITEM_RESULT RESULT3 = new ZK.HIIS.Entities.SEARCH_ITEM_RESULT();
        RESULT3.ORDER = 1;
        ZK.HIIS.Entities.SEARCH_ITEM_RESULT RESULT4 = new ZK.HIIS.Entities.SEARCH_ITEM_RESULT();
        RESULT4.ORDER = 4;
        lst.Add(RESULT1);
        lst.Add(RESULT2);
        lst.Add(RESULT3);
        lst.Add(RESULT4);
        List<ZK.HIIS.Entities.SEARCH_ITEM_RESULT> NewList = lst.OrderByDescending(od1 => od1.ORDER).ToList<ZK.HIIS.Entities.SEARCH_ITEM_RESULT>();//倒序
                List<ZK.HIIS.Entities.SEARCH_ITEM_RESULT> NewList1 = lst.OrderBy(od1 => od1.ORDER).ToList<ZK.HIIS.Entities.SEARCH_ITEM_RESULT>();//顺序



实体类如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ZK.HIIS.Entities
{
    public class SEARCH_ITEM_RESULT
    {
        private int _ORDER = 0;

        public int ORDER
        {
            get { return _ORDER; }
            set { _ORDER = value; }
        }
    }
}
阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/jiancaixing/article/details/6873345
文章标签: search class
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭