'ByRef' parameter '<parametername>' cannot be used in a lambda expression
A lambda expression declared within a Sub
or function cannot use any ByRef
parameters of that Sub
or function. For example, the following code will cause this error because the ByRef
parameter n
is used in the lambda expression.
VB
'' Not valid.
'Sub ExampleSub(ByRef n As Integer)
' Dim lambda = Function(p As Integer) p + n
'End Sub
Error ID: BC36639
Assign the
ByRef
parameter to a local variable, and use the local variable in the lambda expression, as shown in the following code:VBSub ExampleSub(ByRef n As Integer) Dim temp = n Dim lambda = Function(p As Integer) p + temp End Sub
Collaborate with us on GitHub
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, see our contributor guide.
.NET feedback
.NET is an open source project. Select a link to provide feedback: