I know I could use a for
statement and achieve the same effect, but can I loop backwards through a foreach
loop in C#?
When working with a list (direct indexing), you cannot do it as efficiently as using a for
loop.
Edit: Which generally means, when you are able to use a for
loop, it's likely the correct method for this task. Plus, for as much as foreach
is implemented in-order, the construct itself is built for expressing loops that are independent of element indexes and iteration order, which is particularly important in parallel programming. It is my opinion that iteration relying on order should not use foreach
for looping.