我不相信常规方法可以实现这一点,但是类似于这样冗长的代码:
For Each s As String In myStringList Step -1
//' Do stuff here
Next
在传统的 For..Each 循环之前,我可能需要反转 myString 对象,是吗?
首先,在for each语句中创建一个字符串列表,然后再创建一个普通的for循环。看下面的例子:
Dim ff As New List(Of Integer)
For Each rRow As DataRow In DeletedRows
Dim item As Integer
item = rRow.Table.Rows.IndexOf(rRow)
ff.Add(item)
Next
For i As Integer = ff.Count - 1 To 0 Step -1
dim item as integer=ff(i)
next i
希望这有所帮助
接受的答案解释了原因,但是再举一个例子,对于具有键(SortedList、SortedDictionary、Dictionary等)的集合,您可以执行以下操作
For Each Id as Tkey in MyCollection.Keys.Reverse
// The item in question is now available as MyCollection(Id)
Next