I noticed that List
defines its enumerator as a struct
, while ArrayList
defines its enumerator as a class
. What\'s t
Any implementation of IEnumerable
should return a class. It may be useful for performance reasons to have a GetEnumerator
method which returns a struct which provides the methods necessary for enumeration but does not implement IEnumerator
; this method should be different from IEnumerable
, which should then be implemented explicitly.
Using this approach will allow for enhanced performance when the class is enumerated using a foreach or "For Each" loop in C# or vb.net or any context where the code which is doing the enumeration will know that the enumerator is a struct, but avoid the pitfalls that would otherwise occur when the enumerator gets boxed and passed by value.