private static void SimpleQueries2() { var cars = new List <Car> { new Car { CarName = "Opel", MaxSpeed = 240 }, new Car { CarName = "BMW", MaxSpeed = 260 }, new Car { CarName = "BMW", MaxSpeed = 220 }, new Car { CarName = "Audi", MaxSpeed = 250 } }; Console.WriteLine("*** Whole cars:***"); cars.PrintCollection(); Console.WriteLine("*** Fast cars:***"); GetFastCars(cars).PrintCollection(); Console.WriteLine("*** Fast BMWs:***"); GetFastBMWs(cars).PrintCollection(); // BUT!!! // Non-generic collections (such as ArrayList) are not compatible with IEnumerable interface // that is needed for LINQ queries! // so we need to transform them!!! // that also because such containers can contain any type of data!!! var carList = new ArrayList { new Car { CarName = "Opel", MaxSpeed = 240 }, new Car { CarName = "BMW", MaxSpeed = 260 }, new Car { CarName = "BMW", MaxSpeed = 220 }, new Car { CarName = "Audi", MaxSpeed = 250 }, // non-Car objects wont appear in casted list new object(), new Point { X = 2, Y = 3 }, false, 42 }; Console.WriteLine("*** ArrayList collection:***"); // casting (filtering) to IEnumerable<Car> GetFastCars(carList.OfType <Car>()).PrintCollection(); }
public static void RunTests() { const int i = 123456; i.DisplayDefiningAssembly(); var rI = i.ReverseDigits(); Console.WriteLine("i = {0} was changed to - {1}", i, rI); var d = new DataSet(); d.DisplayDefiningAssembly(); var sp = new SoundPlayer(); sp.DisplayDefiningAssembly(); var list = new List<int> {1,2,3,4}; list.PrintCollection(); }
public static void RunTests() { const int i = 123456; i.DisplayDefiningAssembly(); var rI = i.ReverseDigits(); Console.WriteLine("i = {0} was changed to - {1}", i, rI); var d = new DataSet(); d.DisplayDefiningAssembly(); var sp = new SoundPlayer(); sp.DisplayDefiningAssembly(); var list = new List <int> { 1, 2, 3, 4 }; list.PrintCollection(); }
private static void SimpleQueries2() { var cars = new List<Car> { new Car {CarName = "Opel", MaxSpeed = 240}, new Car {CarName = "BMW", MaxSpeed = 260}, new Car {CarName = "BMW", MaxSpeed = 220}, new Car {CarName = "Audi", MaxSpeed = 250} }; Console.WriteLine("*** Whole cars:***"); cars.PrintCollection(); Console.WriteLine("*** Fast cars:***"); GetFastCars(cars).PrintCollection(); Console.WriteLine("*** Fast BMWs:***"); GetFastBMWs(cars).PrintCollection(); // BUT!!! // Non-generic collections (such as ArrayList) are not compatible with IEnumerable interface // that is needed for LINQ queries! // so we need to transform them!!! // that also because such containers can contain any type of data!!! var carList = new ArrayList { new Car {CarName = "Opel", MaxSpeed = 240}, new Car {CarName = "BMW", MaxSpeed = 260}, new Car {CarName = "BMW", MaxSpeed = 220}, new Car {CarName = "Audi", MaxSpeed = 250}, // non-Car objects wont appear in casted list new object(), new Point {X = 2, Y = 3}, false, 42 }; Console.WriteLine("*** ArrayList collection:***"); // casting (filtering) to IEnumerable<Car> GetFastCars(carList.OfType<Car>()).PrintCollection(); }