July 2015
Intermediate to advanced
1300 pages
87h 27m
English
Some extension methods enable you to get the instance of a specified item in a sequence. The first one is Single, and it gets the instance of only the item that matches the specified condition. The following code gets the instance of the only product whose product name is Mozzarella:
Try Dim uniqueElement = products.Single(Function(p) p. ProductName = "Mozzarella")Catch ex As InvalidOperationException 'The item does not existEnd Try
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 ...