直接上代码
//测试数据 public static List<User> myList = new List<User>() { new User(){ID=1, Name="部门1",Age=0,IsChild=false}, new User(){ID=2,Name="部门3",Age=1,IsChild=true}, new User(){ID=3,Name="部门3",Age=1,IsChild=false}, new User(){ID=4,Name="部门2",Age=2,IsChild=false}, new User(){ID=5,Name="部门3",Age=3,IsChild=true}, new User(){ID=6,Name="部门1",Age=4,IsChild=true}, new User(){ID=7,Name="部门2",Age=4,IsChild=true}, new User(){ID=8,Name="部门3",Age=0,IsChild=false}, new User(){ID=9,Name="部门1",Age=0,IsChild=true}, new User(){ID=10,Name="部门3",Age=0,IsChild=false}, }; public static void Main(string[] args) { var q = Test(x => x.ID > 5, x=>new User() { ID=x.ID,Name=x.Name}).ToList(); Console.ReadLine(); } //where 条件 //result 结果 public static IEnumerable<User> Test(Func<User, bool> where,Func<User,User> result) { var q = myList.Where(where); return q.Select(result); } } //假设数据库全字段类型 public class User { public int ID { get; set; } public string Name { get; set; } public int Age { get; set; } public bool? IsChild { get; set; } public User Clone() { return (User)this.MemberwiseClone(); } }