0

I have

Function Bar(s As String) ...

I need to create a function

Me.Foo(myInt, AddressOf Bar)

How should I write the Foo's signature?

2 Answers 2

2

Use of the generic Func(Of Type) keyword is probably the easiest.

Public Function Foo(i As Integer, f As Func(Of String, Integer)) As String
    Dim i2 = f.Invoke("test")
    Return "42"
End Function
Sign up to request clarification or add additional context in comments.

Comments

1

This may help you

Declare your delegate signature:

Public Delegate Sub Format(ByVal value As String)

Define your Test function:

Public Sub CheckDifference(ByVal A As Integer, _
                           ByVal B As Integer, _
                           ByVal format As Format)
    If (B - A) > 5 Then
        format.Invoke(String.Format( _
        "Difference ({0}) is outside of acceptable range.", (B - A)))
    End If
End Sub

Somewhere in your code call your Test function:

CheckDifference(Foo, Bar, AddressOf log.WriteWarn)

Or

CheckDifference(Foo, Bar, AddressOf log.WriteError)

1 Comment

should I really declare a Public Delegate for each king of function call like this, even if I don't use them?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.