[英]VB.NET inline delegate predicate not working
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
Because your “predicate” is not a function 1 , it's a Sub
. 因为您的“谓词” 不是函数1 ,所以它是Sub
。 If you are using the most recent version of VB, you can write the following; 如果您使用的是最新版本的VB,则可以编写以下内容: otherwise, you're out of luck: 否则,您很不走运:
Index = Me.lst_department.FindItem(0, True, Sub(e As ListBoxFindItemArgs) e.IsFound = Object.Equals(ListValue, e.ItemValue))
1 Furthermore, it's not a predicate. 1此外,它不是谓词。 A predicate is a specific type of function having the signature Function(x As T) As Boolean
for some type T
. 谓词是特定类型的函数,对于某些类型T
,其签名为Function(x As T) As Boolean
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.