O'Reilly logo

Microsoft® Visual Basic® 2010 Developer’s Handbook by Klaus Löffelmann and Sarika Calla Purohit

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Aggregate Functions

Aggregate functions are functions that aggregate (add, average, calculate maximum or minimum, or count) the elements in a collection. Unlike normal queries, aggregations pass all items in the collection to an aggregate function that calculates all items, but treats them as a batch.

Note

LINQ queries always start with the From clause—except those that aggregate collections. To run an aggregation of a collection, start the LINQ query with the Aggregate clause instead with the From clause, as shown in the examples in this section.

This first example aggregates the product list into a total, apparently calculating the total sales of articles:

Sub AggregateDemo() Dim feignedSales = Aggregate artElement In prdList Into TotalSum = Sum(artElement.UnitPrice) ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required