I have the following line:
For Each s In groupings
What I want to do is get the first 9 items from groupings.
I tried Fo开发者_如何学Cr 0 to 8 s In groupings
but this didn't work.
Any ideas?
Use Take
:
For Each s In groupings.Take(9)
This will return the first 9 elements in groupings, i.e. indexes 0 to 8.
Update because of your question in the comments:
To get the items at positions 5 to 9, do this:
For Each s In groupings.Skip(5).Take(5)
This will skip the first 5 elements, i.e. indexes 0 to 4 and return the next 5 elements, i.e. indexes 5 to 9.
I would go with Daniel Hilgarth answer, but just for your information, the way you're trying to do would look like this :
For i as integer = 0 to 8 dim s = groupings(i) ... Next i
Have a counter initialized to 0
For Each s In groupings counter =counter+1 ..... If counter=9 Then Exit For Next
(check it, I forgot the syntax)
精彩评论