如何将整个KeyValuePair传递给For循环?
Dim grouped As New Dictionary(Of [String], List(Of DataRow))()
For index = grouped.Count-1 To 0 Step -1
'How do I pass the entire KeyValuePair to the PopulateData function?
PopulateData(????)
Next
答案 0 :(得分:3)
你可以这样做,例如:
Sub Main()
Dim grouped As New Dictionary(Of [String], List(Of DataRow))()
For index = grouped.Count - 1 To 0 Step -1
PopulateData(New KeyValuePair(Of String,
List(Of DataRow))(grouped.Keys(index), grouped.Values(index)))
Next
End Sub
Sub PopulateData(kv As KeyValuePair(Of String, List(Of DataRow)))
End Sub
但是,您正在以这种方式将.NET框架扩展到限制,字典不应该向前或向后迭代。即使您决定迭代它,您的代码也不应该依赖于元素的顺序,否则它可能会在以后中断。