I had a little dispute (which was very close to holy war:) ) with my colleage, about the performance of access to list via indeces VS via enumerator. To operat
If you look at the IL for both versions, you will see that the first version uses an iterator of type System.Collections.Generic.List
-- a nested struct
, which is optimized for iterating over a list.
The second version uses a generic implementation of System.Collections.Generic.IEnumerator
, which is less efficient because it does not "cheat" by keeping a private index to the current item in the list.