Export (0) Print
Expand All
Expand Minimize

Option Strict On requires each lambda expression parameter to be declared with an 'As' clause if its type cannot be inferred

Visual Studio 2008

You have declared a parameter in a lambda expression without using an As clause, with Option Strict on.

' Not valid when Option Strict is on.
' Dim increment1 = Function (n) n + 1

The previous declaration is valid if the type of n can be inferred. For example, if you are assigning the previous lambda expression to a function delegate, Del:

Delegate Function Del(ByVal p As Integer) As Integer

Now the type of n can be inferred from parameter p:

Dim increment2 as Del = Function(n) n + 1

Error ID: BC36642

To correct this error

  • Add an As clause to the parameter declaration:

    Dim increment3 = Function (n As Integer) n + 1

Community Additions

© 2014 Microsoft