Sometime in VB.net i have something like:
For Each El in Collection Write(El) Next
But if i need the index number, i have to change it to
For I = 0 To Collection.Count() - 1 Write(I & " = " & Collection(I)) Next
Or even (worse)
I = 0 For Each El In Collection Write(I & " = " & El) I += 1 Next
Is there another way of getting the index?
If you are using a generic collection (Collection(of T)) then you can use the IndexOf method.
For Each El in Collection Write(Collection.IndexOf(El) & " = " & El) Next
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With