// Create a query expression.
var fastCars = from c in myCars where c.Speed > 55 select c;
foreach (var car in fastCars)
{
Console.WriteLine("{0} is going too fast!", car.PetName);
}
}
Notice that our query expression is only grabbing items from the List where the Speed
property is greater than 55. If we run the application, we will find that “Henry” and “Daisy” are the
only two items that match the search criteria.
If we want to build a more complex query, we might wish to only find the BMWs that have a
Speed value above 90. To do so, simply build a compound Boolean statement using the C# &&
operator:
Do'stlaringiz bilan baham: |