class Pet
{
publicstring Name { get; set; }
publicbool Vaccinated { get; set; }
}
publicstaticvoid CountEx2()
{
Pet[] pets = { new Pet { Name="Barley", Vaccinated=true },
new Pet { Name="Boots", Vaccinated=false },
new Pet { Name="Whiskers", Vaccinated=false } };
try
{
int numberUnvaccinated = pets.Count(p => p.Vaccinated == false);
Console.WriteLine("There are {0} unvaccinated animals.", numberUnvaccinated);
}
catch (OverflowException)
{
Console.WriteLine("The count is too large to store as an Int32.");
Console.WriteLine("Try using the LongCount() method instead.");
}
}