VB.NET 内联委托谓词不起作用
这是我的问题。如果我写这个 -
Private ListValue As Object = Nothing
Private Sub FindIndex(ByVal e As ListBoxFindItemArgs)
e.IsFound = Object.Equals(ListValue, e.ItemValue)
End Sub
Private Sub SearchValues
ListValue = 5
Index = Me.lst_department.FindItem(0, True, AddressOf FindIndex)
End Sub
但我只是不明白为什么这段代码,写来做同样的事情不起作用 -
Private Sub SearchValues
ListValue = 5
Index = Me.lst_department.FindItem(0, True, Function(e As ListBoxFindItemArgs) e.IsFound = Object.Equals(ListValue, e.ItemValue))
End Sub
This is my problem. If I write this -
Private ListValue As Object = Nothing
Private Sub FindIndex(ByVal e As ListBoxFindItemArgs)
e.IsFound = Object.Equals(ListValue, e.ItemValue)
End Sub
Private Sub SearchValues
ListValue = 5
Index = Me.lst_department.FindItem(0, True, AddressOf FindIndex)
End Sub
But I'm just out of my wit why this code, written to do the same thing is not working -
Private Sub SearchValues
ListValue = 5
Index = Me.lst_department.FindItem(0, True, Function(e As ListBoxFindItemArgs) e.IsFound = Object.Equals(ListValue, e.ItemValue))
End Sub
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因为您的“谓词”不是函数1,而是一个
Sub
。如果您使用的是最新版本的VB,您可以编写以下内容;否则,你就不走运了:1 此外,它不是一个谓词。谓词是一种特定类型的函数,对于某种类型
T
具有签名Function(x As T) As Boolean
。Because your “predicate” is not a function1, it’s a
Sub
. If you are using the most recent version of VB, you can write the following; otherwise, you’re out of luck:1 Furthermore, it’s not a predicate. A predicate is a specific type of function having the signature
Function(x As T) As Boolean
for some typeT
.