You can use a For Each...Next
loop to iterate through any IEnumerable
type. This includes arrays, lists, and anything else that may be of type IEnumerable or returns an IEnumerable.
An example of looping through a DataTable's Rows property would look like this:
For Each row As DataRow In DataTable1.Rows
'Each time this loops, row will be the next item out of Rows
'Here we print the first column's value from the row variable.
Debug.Print(Row.Item(0))
Next
An important thing to note is that the collection must not be modified while in a For Each
loop. Doing so will cause a System.InvalidOperationException
with the message:
Collection was modified; enumeration operation may not execute.