Type Inference and Lambda Expressions

At a higher level, lambda expressions fully support local type inference so that the Visual Basic compiler can decide for you the appropriate data type. For lambdas, there is something more to say. Type inference is determined by how you write your code. Consider the first lambda expression at the beginning of this section:

Dim f As Func(Of Double, Double, Double) = Function(x, y) x * y

In the preceding code, local type inference affects both arguments and the result of the Function statement. The compiler can infer Double to the x and y parameters and therefore can determine Double as the result type. This is possible only because we explicitly provided types in the delegate ...

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.