linq check if exists in list 1

linq check if exists in list

using System.Linq;
...
    bool has = list.Any(cus => cus.FirstName == "John");

Here is what the above code is Doing:
1. We’re calling the Any method on the list.
2. We’re passing in a lambda expression that takes a Customer object and returns a bool.
3. The lambda expression is checking to see if the FirstName property of the Customer object is equal to “John”.
4. If any of the Customer objects in the list have a FirstName property equal to “John”, then the Any method will return true.

Similar Posts