- LINQ to Objects refer to the use of LINQ queries with any IEnumerable or IEnumerable<T> collection.
- LINQ to query any enumerable collections such as List<T>, Array, or Dictionary<TKey, TValue>
- LINQ to Objects represents a new approach to collections. In older way, you had to write complex foreach loops that specified how to retrieve data from a collection.
- LINQ queries offer three main advantages over traditional foreach loops:
- They are more concise and readable, especially when filtering multiple conditions.
- They provide powerful filtering, ordering, and grouping capabilities with a minimum of application code.
- They can be ported to other data sources with little or no modification.
How to: Query an ArrayList with LINQ
LINQ to query non-generic IEnumerable collections such as ArrayList, you must explicitly declare the type of the range variable to reflect the specific type of the objects in the collection.
Here I have taken Cricket 's Player class to understand the Linq to Object.
Player contains single properties FirstName,LastName,Country and Multivalue Properties like Scores.List of batsman who have scrored more than 50 runs in their First Match
Sachin Tendulkar: 200
Ricky Ponting: 180
Hashim Amla: 88
Mahela Jayawardene: 97
Press any key to exit.
To get same output with query operator,
Replace above query part with below code.
Linq And String
LINQ and File Directories
LINQ and Reflection
How to: Add Custom Methods for LINQ Queries