1
爲什麼此方法不對列表中的值進行排序?OrderBy使用泛型的IEnumerable
public Paging(IEnumerable<T> values, int start, int limit, string property, string dir)
{
this.Total = values.Count();
Func<T, string> func = a => a.GetType().GetProperty(property).Name;
IEnumerable<T> order = null;
if (dir == "DESC")
order = values.OrderByDescending(func);
else
order = values.OrderBy(func);
if ((start + limit) > this.Total)
limit = this.Total - start;
IEnumerable<T> items = (start < 0 || limit < 0) ? order : order.Skip(start).Take(limit);
this.AddRange(items);
}
OrderByDescending不存在。使用order = values.OrderBy(property +「DESC」);或order = values.OrderBy(property); – Gus
@格斯:很好!我修好了。 – mellamokb