# Any 是判断列表里面是否有满足条件的(至少一个)
bool res = masterList.Any(x=>x.name == "小明"); |
# All 是判断列表里面是否每一项都包含
bool res = masterList.All(x=>x.identity == "打工人"); |
同时,Any () 方法常常可以用来检查列表是否为空。如果列表中有一个元素,则 List.Any () 函数将返回 true;否则返回 false。
if(empytList.Any()) | |
{ | |
Console.WriteLine("Not Empty") | |
} | |
else | |
{ | |
Console.WriteLine("List is Empty") | |
} |