123
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace LinqAndCollections { class Program { static void Main(string[] args) { List<Car> Cars = new List<Car>() { new Car {PetName="BMW",Color="1234",Speed=10,Make=123456 }, new Car {PetName="Lada",Color="1234",Speed=20,Make=123456 }, new Car {PetName="Mitsubishi",Color="1234",Speed=30,Make=123456 }, new Car {PetName="Ferrari",Color="1234",Speed=40,Make=123456 } }; GetFastCars(Cars); Console.WriteLine(" "); GetFastFerrari(Cars); Console.ReadLine(); } static void GetFastCars(List<Car> Cars) { var fastCars = from c in Cars where c.Speed > 20 select c; foreach (var car in fastCars) Console.WriteLine(car.PetName); } static void GetFastFerrari(List<Car> Cars) { var fastCarsBMW = from c in Cars where c.Speed > 20 && c.PetName == "Ferrari" select c; foreach (var car in fastCarsBMW) Console.WriteLine(car.PetName); } } class Car { public string PetName { get; set; } public string Color { get; set; } public int Speed { get; set; } public int Make { get; set; } } } |