簡體   English   中英

VB.NET內聯委托謂詞不起作用

[英]VB.NET inline delegate predicate not working

這是我的問題。 如果我寫這個-

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

因為您的“謂詞” 不是函數1 ,所以它是Sub 如果您使用的是最新版本的VB,則可以編寫以下內容: 否則,您很不走運:

Index = Me.lst_department.FindItem(0, True, Sub(e As ListBoxFindItemArgs) e.IsFound = Object.Equals(ListValue, e.ItemValue))

1此外,它不是謂詞。 謂詞是特定類型的函數,對於某些類型T ,其簽名為Function(x As T) As Boolean

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM