像List.Exists(谓词)这样的LINQ方法?

mar*_*l82 1 c# linq

我正在寻找像LINQ这样的方法List.Exists(predicate).

bool exists = mylist.Exists(p => p.Name == "Kamila");

bool exists = collection.??????(p => p.Name == "Kamila");
Run Code Online (Sandbox Code Playgroud)

Gil*_*een 6

使用.Any方法:

//Will return true (and stop future iteration the moment the predicate is met)
//Otherwise false
bool exists = collection.Any(p => p.Name == "Kamila");
Run Code Online (Sandbox Code Playgroud)

  • 另一种方法:`collection.Select(p => p.Name).Contains("Kamila")` (3认同)