Sub Lambdas

So far you have seen lambda expressions that were represented only by functions that could return a value and that were realized via the Function keyword. You can also use Sub lambdas that C# developers know as anonymous methods. This feature lets you use the Sub keyword instead of the Function one so that you can write lambda expressions that do not return a value. The following code demonstrates this:

Dim collection As New List(Of String) From {"Alessandro",                                      "Del Sole",                                      alessandro.delsole@visual-basic.it"}collection.ForEach(Sub(element) Console.WriteLine(element))

The preceding code iterates a List(Of String) collection and sends ...

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.