这看起来应该是非常容易做到的事情,但每次我处理这个问题时,我最终都会感到“不够优雅”的解决方案 这是我的基本问题:如果我循环浏览我以特定方式排序的字典,在循环中的任何给
这是我的基本问题:如果我循环浏览我以特定方式排序的字典,在循环中的任何给定点内如何“窥视”或引用字典项“x”位于当前位置之前项目而不更改当前的枚举器?例如:
Dim tempDictionary = New Dictionary(Of String, String)
tempDictionary.Add("TestName1", "TestValue1")
tempDictionary.Add("TestName2", "TestValue2")
tempDictionary.Add("TestName3", "TestValue3")
'... and so on ... '
For Each Item In tempDictionary
DoStuff(Item)
'Here is the point in which I want to see what the value of the'
'dictionary item that is 1, 2, 3, [x] places in front of the current'
'item without interfering w/ the current loop.'
'CODE'
Next
提前致谢!
声音就像你想要一个c风格的循环.在这里原谅C#(因为你在VB中问过)for (int i = 0; i < myArray.Length; i++) {
object current = myArray[i];
if(i + 1 < myArray.Length) { // make sure there is a next item
object nextItem = myArray[i + 1]
}
}
如上所述,字典不是有序的,但您可以将Keys放在一个数组中以使用上面的内容.
