I BELIEVE I CAN

加油,努力,奋斗!!

导航

List<T> 排序

List<T> 排序

不说什么了,直接贴代码

  1 //Compare records  by selected column
  2    internal class ListComparer<T> : IComparer<T>
  3    {
  4        private string propertyName;
  5
  6        public ListComparer(string PropertyName)
  7        {
  8            propertyName = PropertyName;
  9        }

 10
 11        IComparer Members
106    }

107
108    //Sort list by sort field and  sortDirection.
109    public class SortList<T>
110    {
111        public static void Sort(List<T> list, string sortfield, bool isAscending)
112        {
113            ListComparer<T> listComparer = new ListComparer<T>(sortfield);
114            list.Sort(listComparer);
115            if (!isAscending) list.Reverse();
116        }

117    }

 

我们调用的时候,直接排序

 SortList<Model>.Sort(IListModel as List<Model>, "Name", true);

posted on 2009-01-14 09:20  朱小能  阅读(743)  评论(0)    收藏  举报