For Each loops are bad, mmmKay?
I avoid them for 2 main reasons:
1. Index loops are faster.
2. You cant modify a list inside a For Each loop.
I'll explain.
This will fail at the remove call:
For Each str As String In lstStr
'test for something
If str = "boosh"
lstStr.Remove(str)
End If
Loop
It fails because you have changed the list count and therefor the index.
This however, will work:
For i As Integer = lstStr.Count -1 To 0 Step -1
'test for something
If lstStr(i) = "boosh"
lstStr.RemoveAt(i)
End If
Next
This
one works because we start at the bottom of the list and work up. So
if we remove something it only affects where we've already been.