public static List<T> SortAsc<T>(List<T> source, string sortby)
{
List<T> tlist = source.OrderBy(x => x.GetType().GetProperty(sortby)).ToList<T>();
return tlist;
}
这个方法我写的,测试根本没排序,求大神指点迷津
默认是升序,你按降序试试,有可能是因为排序后的结构跟原来的一样,List tlist = source.OrderByDescending(x => x.GetType().GetProperty(sortby)).ToList();
List<T> tlist = source.OrderBy(x => x.GetType().GetProperty(sortby)).ToList<T>();
->
List<T> tlist = source.OrderBy(x => x.GetType().GetProperty(sortby).GetValue(x, null)).ToList<T>();