LINQ - Different ways to Query an Arraylist
By [)ia6l0 iii
An Arraylist is a non-generic collection object that does not implement IEnumerable<T> interface. To query such an object , you have two ways.
a) Use the Cast<T> operator:
The Cast operator converts a non-generic object to a generic object that implements
ArrayList machines = GetMachines();
var query = from machine in machines.Cast<Computer>()
where machine.Type = 1
b) Declare the type of variable to specify the type of object in the collection.
var query = from Computer s in machines
The main speciality of LINQ is that you write queries to select/manipulate data from any kind of data source. The same code works for database, XML or any objects like Entities.
Use the link attribute to link a style sheet to your web page
Use the ToCharArray with the Linq Reverse method.
var data = Enumerable.Range(100,10).ToArray();
You can use ternary operator to handle null values in LINQ query. See the following example.
We can use LINQ to initialize elements of an array with a specified range of values. The following statement initializes an interger array with values of 20-29.
LINQ - Different ways to Query an Arraylist (1058 Views)