C# Linq处理 Where条件筛选

节选自C# Linq处理list数据http://www.cnblogs.com/cang12138/p/5305629.html

//将provice=吉林的筛选出来。
list = list.Where(x => x.provice == "吉林").ToList();
//将包含1,5条件的数据筛选出来,相当于sql里的in用法:select * from 表 where user_type in (1,5)
list= list.Where(a => "1,5".Contains(a.user_type)).ToList();
//此处等同于上面
list= list.Where(a => a.user_type == "1" || a.user_type == "5").ToList();
//另一种形式,from开头
IList query = (from item in list
                      where ("," + projectmodel.ids + ",").Contains("," + item.id + ",")
                      select item).ToList();
//两个条件
list = list.Where(x => x.provice == "吉林"&&a.user_type == "1").ToList();


你可能感兴趣的:(c#)