易丰科技
标题:
C# LINQ Any Example
[打印本页]
作者:
Calvin
时间:
2011-10-7 15:30
标题:
C# LINQ Any Example
class Pet
{
public string Name { get; set; }
public int Age { get; set; }
public bool Vaccinated { get; set; }
}
public static void AnyEx2()
{
// Create an array of Pets.
List<Pet> PetList =
{
new Pet { Name="Barley", Age=8, Vaccinated=true },
new Pet { Name="Boots", Age=4, Vaccinated=false },
new Pet { Name="Whiskers", Age=1, Vaccinated=false }
};
// Determine whether any pets over age 1 are also unvaccinated.
bool unvaccinated = PetList.Any(p => p.Age > 1 && p.Vaccinated == false);
Console.WriteLine(
"There {0} unvaccinated animals over age one.",
unvaccinated ? "are" : "are not any");
}
复制代码
欢迎光临 易丰科技 (http://forum.yftek.com/)
Powered by Discuz! X3