I’m using the following syntax to loop through a list collection:
For Each PropertyActor As JCPropertyActor In MyProperty.PropertyActors i = IndexOf(PropertyActor) Next
How do I get the index of the current object within the loop? I’m using IndexOf(PropertyActor) but this seems inefficient as it searches the collection when I already have the object available!
An index doesn’t have any meaning to an IEnumerable, which is what the foreach construct uses. That’s important because
foreachmay not enumerate in index order, if your particular collection type implements IEnumerable in an odd way. If you have an object that can be accessed by index and you care about the index during an iteration, then you’re better off just using a traditional for loop: