How to convert nested foreach loops with conditions to LINQ

前端 未结 4 821
小蘑菇
小蘑菇 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:53

    I'm not sure exactly how far you want to go with this, but this is a Linq statement doing the same thing:

    listA.ForEach(a => listB.ForEach(b =>
    {
        if (b.IsCorrect(a)) b.DoSomething(a);
    }));
    

提交回复
热议问题