0

I need to create the exact same program as these but without using foreach. I need to use .find and lambda expressions. I am trying to solve this problem for one week without any luck.

Action delljack = () =>
                {
                    
                    foreach (Gost x in list.listofguests)
                    {

                        if (x.name == "jack")
                        {

                            Console.WriteLine("There is jack in my list");

                            return;

                        }
                    }
                };

1 Answers1

2

In order to do the same as your lambda without using foreach you can use linq:

    if (list.listofguests.Any(x => x.name == "jack"))
        Console.WriteLine("There is jack in my list");

To get more information you can read about linq here https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/linq/

Fuffelschmerz
  • 150
  • 1
  • 10