For using Language Integrated Query into array we will first declare an array of items
I have created array list of cars in which i have name and its color as the list item associated with this list
/* Array of cars manipulateed by the LINQ query */
ArrayList myCars = new ArrayList();
myCars.Add(new Car{ Name= "Cruze", Color = "Silver"}); myCars.Add(new Car{ Name = "Ecosport", Color = "Rust"});
myCars.Add(new Car { Name = "Baleno", Color = "White"});
IEnumerable<Car> myCarsEnum = myCars.OfType<Car>();
// Create a query expression.
var fastCars = from c in myCarsEnum select c;
foreach (var car in fastCars)
{
Console.WriteLine("{0} is going too fast!", car.Name);
}
In this LINQ query we have a collection of fast cars which we are printing it one by one .
We have used the IEnumerable collection that is used for the collection of cars from an array after doing this we will perform the LINQ query to store all these cars into the variable var and then we print the cars one by one.
0 Comment(s)