I'm looking for LINQ method like List.Exists(predicate)
.
bool exists = mylist.Exists(p => p.Name == "Kamila");
bool exists = collection.??????(p => p.Name == "Kamila");
I'm looking for LINQ method like List.Exists(predicate)
.
bool exists = mylist.Exists(p => p.Name == "Kamila");
bool exists = collection.??????(p => p.Name == "Kamila");
Use the .Any
method:
//Will return true (and stop future iteration the moment the predicate is met)
//Otherwise false
bool exists = collection.Any(p => p.Name == "Kamila");
You are looking for Any
:
bool exists = collection.Any(p => p.Name == "Kamila");
It is an Extension Method for any IEnumerable<T>
defined on System.Linq.Enumerable
.
Check this post for more details: Linq .Any VS .Exists - Whats the difference?