Start the cycle with a specific index in vb.net?

Is there a way to start with a non-zero index when using a for each loop in vb?

I got an error "The input string was not in the correct format" when trying:

For Each segment As String in p

If not p(0) Then

+5
source share
5 answers

You can use the LINQ Enumerable.Skip method to reduce your list before repeating it:

For Each segment As String in p.Skip(1)
    ...
Next
+7
source

I think your misunderstanding of the difference between for eachand for.

for eachwill go through each element of the array forwill go through the indices of the array

for i = 0 to p.size //change 0 to the index you want to start
    p(i)
    ...
next
+3
source

,

for each segment as string in p.Skip(1)
. . . .
next

5 . . . in p.Skip(5)

+1

Skip, lambda, , .

The lambda will list as a foreach loop, but it will also call the delegate passed to it as an argument to check the condition.

+1
source

Assuming it phas an index, for example, ArrayorIList

For i As Integer = 1 To p.Count - 1
    p(i)
Next

It is assumed that you are using standard Option Base 0

+1
source

All Articles