How to convert nested foreach loops with conditions to LINQ

前端 未结 4 830
小蘑菇
小蘑菇 2021-01-16 14:57

I\'d like to ask if it is possible to convert below nested foreach loops to LINQ expression.

public interface IFoo
{
  bool IsCorrect(IFoo foo);
  void DoSom         


        
4条回答
  •  醉酒成梦
    2021-01-16 15:49

    This should work:

    var result =
        from a in listA
        from b in listB
        where b.IsCorrect(a)
        select new {a, b};
    
    foreach (var item in result)
        item.b.DoSomething(item.a);
    

提交回复
热议问题