我想知道是否可以在 Next 语句之前获得 For Each 中 Next 值的值
如果我有这个代码:
For Each i As String In myStringArray
'Do Something with i
Next
我可以有类似的东西,只有我正在做或检查下一个值:
For Each i As String In myStringArray
'Do Something with i
'Check the Next Value of i
Next
您可以做相反的事情并保留最后一项,但要采取行动:
Dim last As String = Nothing
For Each i As String In myStringArray
If last IsNot Nothing Then
' Treat last as current, i as next
End If
last = i
Next
不要使用for each
循环,使用for
循环并索引到数组中。
For index As Integer = 0 To myStringArray.Length
...
Next
No not in a for each,但如果它是一个数组,你可以使用 index 代替
For i As Integer = 0 To myStringArray.Length - 1
Dim s As String = myStringArray(i)
'Do Something with s
If i - 1 < myStringArray.Length Then
Dim nexts as String = myStringArray(i + 1)
'Check the Next Value of s = nexts
End If
Next