List<Student> lsStudent = new List<Student>(){ new Student { ID = 1,Name = "1", Age = 128, Sex = null }, new Student { ID = 2, Name = "2", Age = 18, Sex = "女" }, new Student { ID = 3, Name = "31", Age = 13, Sex = "男" }, new Student { ID = 4, Name = "4", Age = 23, Sex = "男" }, new Student { ID = 5, Name = "51", Age = null, Sex = "女" }, new Student { ID = 6, Name = "6", Age = null, Sex = "女" }, new Student { ID = 7, Name = "7", Age = null, Sex = "女" } };
模糊查询条件:根据Name=1或者Sex=女模糊查询 string key = “1”; string sex = “女”;
方法一 List<Student> resultList = (from c in lsStudent where c.Name.Contains(key) ||c.Sex.Contains(sex) select c).ToList();