You get this error because the delegate type of the (ByVal z As Double) As String function is not compatible with the (ByRef z As Double) As String function . You need an exact match.
Also, you cannot declare a common Func (Of ...) delegate with ByRef (ref or out in C #) parameters, regardless of whether you use an anonymous function or not.
But you can declare a delegation type and then use it even with an anonymous function
Delegate Function ToStringDelegate(ByRef value As Double) As String Sub Main() Dim Del As ToStringDelegate = Function(ByRef value As Double) value.ToString() End Sub
or you can use implicit typing (if the Infer parameter is enabled)
Dim Del = Function(ByRef value As Double) value.ToString()
Artyom krivokrisenko
source share