Elements Operators

There are some extension methods that allow getting the instance of a specified item in a sequence. The first one is Single that gets the instance of only the item that matches the specified condition. For example, the following code gets the instance of the only product whose product name is Mozzarella:

image

Single takes a lambda expression as an argument in which you can specify the condition that the item must match. It returns an InvalidOperationException if the item does not exist in the sequence (or if more than one element matches the condition). As an alternative you can invoke SingleOrDefault, which returns a default value ...

Get Visual Basic® 2010 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.