【发布时间】:2012-07-23 23:53:26
【问题描述】:
我有
Function Bar(s As String) ...
我需要创建一个函数
Me.Foo(myInt, AddressOf Bar)
Foo的签名应该怎么写?
【问题讨论】:
我有
Function Bar(s As String) ...
我需要创建一个函数
Me.Foo(myInt, AddressOf Bar)
Foo的签名应该怎么写?
【问题讨论】:
使用泛型 Func(Of Type) 关键字可能是最简单的。
Public Function Foo(i As Integer, f As Func(Of String, Integer)) As String
Dim i2 = f.Invoke("test")
Return "42"
End Function
【讨论】:
声明您的代表签名:
Public Delegate Sub Format(ByVal value As String)
定义你的测试函数:
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
在您的代码中的某处调用您的测试函数:
CheckDifference(Foo, Bar, AddressOf log.WriteWarn)
或者
CheckDifference(Foo, Bar, AddressOf log.WriteError)
【讨论】: