LINQ + Foreach vs Foreach + If

前端 未结 4 1618
醉梦人生
醉梦人生 2020-12-02 09:55

I need to iterate over a List of objects, doing something only for the objects that have a boolean property set to true. I\'m debating between this code

for         


        
4条回答
  •  情书的邮戳
    2020-12-02 10:18

    I prefer this:

    theList.Where(itm => itm.Condition).ToList().ForEach(itmFE => { itmFe.DoSomething(); }); 
    

提交回复
热议问题