# Any 是判断列表里面是否有满足条件的(至少一个)

p
bool res = masterList.Any(x=>x.name == "小明");

# All 是判断列表里面是否每一项都包含

p
bool res = masterList.All(x=>x.identity == "打工人");

同时,Any () 方法常常可以用来检查列表是否为空。如果列表中有一个元素,则 List.Any () 函数将返回 true;否则返回 false。

p
if(empytList.Any())
{
    Console.WriteLine("Not Empty")
}
else
{
    Console.WriteLine("List is Empty")
}
更新于 阅读次数

请我喝[茶]~( ̄▽ ̄)~*

Roc 微信支付

微信支付

Roc 支付宝

支付宝