I'm considering a class that uses a generic type (though this isn't directly important to the question here) and allows the user to specify an optional strategy function when instantiating a class object. The problem I'm having is figuring out how to specify a default value for this in New(). I'd like to allow something like this:case A:    Private policy As Func(Of Integer, Integer)    Public Sub New(Optional ByVal g As Func(Of Integer, Integer) =                              Function(ByVal a As Integer) as Integer                                  <some code here>                                  return <some integer value>                              End Function)        policy = g    End SubI hope that's clear enough. The idea is that the New function should accept no parameters, when the default policy function is to be used. What I'm getting is an error telling me that I need a constant value. So I considered this:case B:    Private policy As Func(Of Integer, Integer)    Private Shared Function defaultpolicy(ByVal a As Integer) As Integer        <some code here>        return <some integer value>    End Function    Public Sub New(Optional ByVal g As Func(Of Integer, Integer) = AddressOf defaultpolicy)        policy = g    End SubBut that also does not work in VB.NET, so far as I've been able to uncover so far.Just to be complete, this does work:case C:    Private policy As Func(Of Integer, Integer)    Private Shared Function defaultpolicy(ByVal a As Integer) As Integer        <some code here>        return <some integer value>    End Function    Public Sub New()        Me.New(AddressOf defaultpolicy)    End Sub    Public Sub New(ByVal g As Func(Of Integer, Integer))        policy = g    End SubBut that is NOT how I want to express it. It works. It does what I need it to do, but it leaves me wondering if/how I might actually be able to specify a default anonymous function in the case where I actually DO want to make the parameter Optional, rather than defining TWO New() functions. I'm not just trying to write code that solves a problem. I want to know if VB.NET has syntax to support how I'd like to phrase it. I may not need it here, but someday I may in some other context, and I'd like to know if there is syntax to express my semantic desire here other than the above one that I've identified as working but not expressed in the syntax I'd prefer.Does anyone have an idea how to specify a default anonymous function in case A or case B? (I already have case C, so I don't want to hear a repetition of what I already know.)Thanks in advance.EDIT: I'm guessing that VB.NET (and C#, probably as well) does not permit run-time constant values to be used. Since the address of the anonymous function (or any function) cannot be determined until run-time, it's probably just not possible here. So perhaps VB.NET permits default initial values if and only if they are compile-time constant values. Just a thought. But if anyone knows how to achieve the above... I'd love to hear about it. Thanks.
Specifying a default value for an optional anonymous function parameter in VB.NET
parameters;lambda;default values