Vb.net 对于每一个,下一个值在下一个之前
我想知道在下一个语句之前,是否可以在For Each中获得下一个值的值 如果我有此代码:Vb.net 对于每一个,下一个值在下一个之前,vb.net,foreach,Vb.net,Foreach,我想知道在下一个语句之前,是否可以在For Each中获得下一个值的值 如果我有此代码: 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 不要对每个循环使用,对循环使
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
不要对每个循环使用
,对
循环使用,并索引到数组中
For index As Integer = 0 To myStringArray.Length
...
Next
不在for each中,但如果它是数组,则可以使用索引
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
对于myStringArray.Length-1,i As Integer=0
作为字符串的Dim s=myStringArray(i)
“用它做点什么
如果i-1
你可以做相反的事情,保留最后一项,但要按照它去做:
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
+1因为如果可能(取决于周围的代码),这是一个更干净的解决方案,然后是基于索引循环的解决方案。