I noticed that List<T> defines its enumerator as a struct, while ArrayList defines its enumerator as a class. What’s the difference? If I am to write an enumerator for my class, which one would be preferable?
EDIT: My requirements cannot be fulfilled using yield, so I’m implementing an enumerator of my own. That said, I wonder whether it would be better to follow the lines of List<T> and implement it as a struct.
Like this others, I would choose a class. Mutable structs are nasty. (And as Jared suggests, I’d use an iterator block. Hand-coding an enumerator is fiddly to get right.)
See this thread for an example of the list enumerator being a mutable struct causing problems…