vb.net - How do you pass a lambda function into a regular function as a default value for a conditional argument? -
the following:
delegate function operationdelegate(byval x double) double public function test(optional byref operation operationdelegate = addressof defaultoperation) double return operation.invoke(3) end function gives me error: constant expression required. addressof defaultoperation causing error using visual studio 2013.
i have tried defining defaultoperation in 2 following ways.
public function defaultoperation(byval x double) double return x end function dim defaultoperation operationdelegate = function(x double) double return x end function in either case has not worked. ressource have been using: https://msdn.microsoft.com/en-us/library/bb531253.aspx
anyways time.
a similar questions found:
as suggested in comments on original post, lambda can not used optional parameter.
an alternative overload function (test, in example) version no parameters , version delegate parameter.
delegate function operationdelegate(byval x double) double public function test() double return test(addressof operationdelegate) end function public function test(operation operationdelegate) double return operation.invoke(3) end function
Comments
Post a Comment