Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 是否存在类似List.Exists的LINQ方法(谓词)?_C#_Linq - Fatal编程技术网

C# 是否存在类似List.Exists的LINQ方法(谓词)?

C# 是否存在类似List.Exists的LINQ方法(谓词)?,c#,linq,C#,Linq,我正在寻找像List.existsprediate这样的LINQ方法 使用以下方法: 使用以下方法: 您正在寻找: 它适用于System.Linq.Enumerable上定义的任何对象 查看此帖子了解更多详细信息:您正在寻找: 它适用于System.Linq.Enumerable上定义的任何对象 查看此帖子以了解更多详细信息:链接到文档,+1。我很欣赏。@MikeEason-我总是试图攻击如此多的文档-许多人工作非常努力-为什么不给予赞扬:另一种方法:collection.Selectp=>p.

我正在寻找像List.existsprediate这样的LINQ方法

使用以下方法:

使用以下方法:

您正在寻找:

它适用于System.Linq.Enumerable上定义的任何对象

查看此帖子了解更多详细信息:

您正在寻找:

它适用于System.Linq.Enumerable上定义的任何对象


查看此帖子以了解更多详细信息:

链接到文档,+1。我很欣赏。@MikeEason-我总是试图攻击如此多的文档-许多人工作非常努力-为什么不给予赞扬:另一种方法:collection.Selectp=>p.Name.containskamilla另一种方法不可读:!collection.Allp=>p.Name!=Kamila用于链接到文档,+1。我很欣赏。@MikeEason-我总是试图攻击如此多的文档-许多人工作非常努力-为什么不给予赞扬:另一种方法:collection.Selectp=>p.Name.containskamilla另一种方法不可读:!collection.Allp=>p.Name!=卡米拉吉拉德·格林快了6秒:,但是+1表示回答正确。@marbel82是的。我喜欢这种行为吉拉德·格林快了6秒:,但是+1表示回答正确。@marbel82是的。我喜欢这种行为
bool exists = mylist.Exists(p => p.Name == "Kamila");

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