C# List集合使用where,foreach条件过滤多种用法

where里多个条件进行查询

1.
list.Where(a =>string.IsNullOrWhiteSpace(a.Id) && (!a.Called || (a.Called && _checkCalled.Checked))).ToList();
2.
list= list.Where(a => "1,5".Contains(a.Stuid)).ToList();
相当于SQL语句 select * from Study where Stuid in (1,5);

Foreach
1.指定某条数据 Check为true
 list.ForEach((itm) =>
                   {
    
    
                     if (txtOsaCbiMemolst.Tag.ToString().Contains(itm.BiId))
                        {
    
    
                          itm.Check = true;
                        }
                    });
 2.全部为true
   list.ForEach(m=>m.Check = true);
  


猜你喜欢

转载自blog.csdn.net/China_Marcy/article/details/105382956