Asp.net 尝试让VB匿名方法工作。查询列表
我正试图让我的代码按照上的说明工作 到目前为止,我有包装纸:Asp.net 尝试让VB匿名方法工作。查询列表,asp.net,vb.net,list,predicate,anonymous-methods,Asp.net,Vb.net,List,Predicate,Anonymous Methods,我正试图让我的代码按照上的说明工作 到目前为止,我有包装纸: Public Delegate Function PredicateWrapperDelegate(Of T, A)(ByVal item As T, ByVal argument As A) As Boolean Public Class PredicateWrapper(Of T, A) Private _argument As A Private _wrapperDelegate As PredicateWrap
Public Delegate Function PredicateWrapperDelegate(Of T, A)(ByVal item As T, ByVal argument As A) As Boolean
Public Class PredicateWrapper(Of T, A)
Private _argument As A
Private _wrapperDelegate As PredicateWrapperDelegate(Of T, A)
Public Sub New(ByVal argument As A, _
ByVal wrapperDelegate As PredicateWrapperDelegate(Of T, A))
_argument = argument
_wrapperDelegate = wrapperDelegate
End Sub
Private Function InnerPredicate(ByVal item As T) As Boolean
Return _wrapperDelegate(item, _argument)
End Function
Public Shared Widening Operator CType( _
ByVal wrapper As PredicateWrapper(Of T, A)) _
As Predicate(Of T)
Return New Predicate(Of T)(AddressOf wrapper.InnerPredicate)
End Operator
End Class
然后我有一个我修改过的函数,使用我的部门id变量(did)
然后我尝试从我的代码调用它:
Dim children As List(Of String) = toplevel.FindAll(New PredicateWrapper(Of Integer, Integer)(Did, AddressOf DidMatch))
然后我在DidMatch上得到一个错误。。。错误方法“公共函数DidMatch(项作为DeptMenuData,did作为整数)作为布尔值”没有与委托“委托函数PredicateWrapperDelegate(属于整数,整数)(项作为整数,参数作为整数)作为布尔值”兼容的签名
你能看出我做错了什么吗
谢谢。更改:
Dim children As List(Of String) = toplevel.FindAll(New PredicateWrapper(Of Integer, Integer)(Did, AddressOf DidMatch))
致:
Dim children As List(Of String) = toplevel.FindAll(New PredicateWrapper(Of Integer, Integer)(Did, AddressOf DidMatch))
Dim children As List(Of String) = toplevel.FindAll(New PredicateWrapper(Of ListDataItem, Integer)(Did, AddressOf DidMatch))