项目查询数据库使用的是linq 语法,可是后期需要用到不同字段的排序.各种纠结! 在网上找了各种资料 后面才找到两种方法 using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.Reflection; using System.Text; namespace Rose.Repository.Repositories { public
class Pet { public string Name{get;set;} public int Age{get;set;} } void Main() { Pet[] pets = { }, }, } }; //如果我们想根据Age进行排序 很容易想到这样来写: var query= from p in pets orderby p.Age select p; query.ToList().ForEach(q=>Console.WriteLine(q.Name +" "+