LINQ TO OBJECTS

LINQ to Objects refers to methods that let a program extract data from objects that are extended by LINQ extension methods. These methods extend IEnumerable(Of T) so that they apply to any class that implements IEnumerable(Of T) including Dictionary(Of T), HashSet(Of T), LinkedList (Of T), Queue(Of T), SortedDictionary(Of T), SortedList(Of T), Stack(Of T), and others.

For example, the following code searches the all_customers list for customers with negative account balances. It orders them by account balance and returns their names and balances.

Dim overdue_custs =
    From cust In all_customers
    Where cust.AccountBalance < 0
    Order By cust.AccountBalance Ascending
    Select cust.Name, cust.AccountBalance

The result of this query is an IEnumerable object that the program can iterate through to take action for the selected customers.

All of the examples shown previously in this chapter use LINQ to Objects, so this section says no more about them. See the previous sections for more information and examples.

Get Visual Basic 2012 Programmer's Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.