Is it possible to do a For…Each Loop Backwards?

前端 未结 13 2164
没有蜡笔的小新
没有蜡笔的小新 2020-12-06 03:53

I don\'t believe this is possible by conventional methods, but something like this verbose code:

For Each s As String In myStringList Step -1
    //\' Do stu         


        
13条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-06 04:47

    The accepted answer explains why, but to add another example, for a collection with key (SortedList, SortedDictionary, Dictionary, etc.) you can do

    For Each Id as Tkey in MyCollection.Keys.Reverse
       // The item in question is now available as MyCollection(Id)
    Next
    

提交回复
热议问题