Lambda expressions are not valid in the first expression of a 'Select Case' statement

 

Updated: July 20, 2015

You cannot use a lambda expression for the test expression in a Select Case statement. Lambda expression definitions return functions, and the test expression of a Select Case statement must be an elementary data type.

The following code causes this error:

' Select Case (Function(arg) arg Is Nothing)  
    ' List of the cases.  
' End Select  

Error ID: BC36635

To correct this error

  • Examine your code to determine whether a different conditional construction, such as an If...Then...Else statement, would work for you.

  • You may have intended to call the function, as shown in the following code:

    Dim num? As Integer  
    Select Case ((Function(arg? As Integer) arg Is Nothing)(num))  
        ' List of the cases  
    End Select  
    
    

Lambda Expressions
If...Then...Else Statement
Select...Case Statement

Show: