【发布时间】:2012-04-24 09:51:55
【问题描述】:
我知道我可以使用 for 循环来做到这一点,因为我现在就是这样做的。我希望有一种更有效的方式来完成这项任务。
我有一本字典(整数,布尔值) 或字符串,布尔值。 我想从字典中获取一个列表(整数)或字符串,其中所有值都是真(或假,取决于我当时需要什么)
为了概括它或“黑盒”它,它可以是任何字典(无论什么,什么) 并返回一个列表(不管),其中值 = 我当时正在寻找的任何东西。
字符串,字符串 where value = "Closed"
简而言之:我想要所有键值的所有列表 = 一些标准
我当前的代码:
Public Function FindInDict(Of tx, ty)(thedict As Dictionary(Of tx, ty), criteria As ty) As List(Of tx)
Dim tmpList As New List(Of tx)
For xloop As Integer = 0 To thedict.Count - 1
If CType(thedict(thedict.Keys(xloop)), ty).Equals(criteria) Then
tmpList.Add(thedict.Keys(xloop))
End If
Next
Return tmpList
End Function
【问题讨论】:
-
我认为 For 循环可能是你最好的选择。但我可能错了
-
另外,我可以像 myList.Find(criteria) 或 myList.FindAll(criteria) 那样做,有没有等效的字典?
标签: vb.net