Multiline Lambdas

With multiline lambdas, you have the ability to write complete anonymous delegates within a line of code, as demonstrated in the following snippet:

Console.WriteLine("Enter a number:")Dim number = CDbl(Console.ReadLine)Dim result = Function(n As Double)                 If n < 0 Then                     Return 0                 Else                     Return n + 1                 End If             End FunctionConsole.WriteLine(result(number))

In this particular case, the compiler can infer the System.Func(Of Double, Double) result type because the n argument is of type Double. Within the method body, you can perform required evaluations, and you can also explicitly specify the return type (take ...

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.