Quantifiers

LINQ offers two interesting extension methods for sequences, Any and All. Any checks whether at least one item in the sequence satisfies the specified condition. For example, the following code checks whether at least one product name contains the letters “of”:

Dim result = products.Any(Function(p) p.ProductName.Contains("of"))

The method receives a lambda as an argument that specifies the condition and returns True if the condition is matched. All checks whether all members in a sequence match the specified condition. For example, the following code checks whether all products are discontinued:

Dim result = products.All(Function(p) p.Discontinued = True)

As previously noted, ...

Get Visual Basic 2015 Unleashed 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.