Posterous theme by Cory Watilo

This is wrong : Why enumerator structs are a really bad idea

If you've ever poked around the .NET class libraries in Reflector, you probably would have noticed that the generic collection classes all have implementations of their IEnumerator as a struct rather than a class. As you will see, this design decision has some rather unfortunate side effects...

The "side-effects" that are talked about here are the natural effects of dealing with a value-type. The same behavior would happen if he was wrapping an Int32.

The 99% use-case of a generic enumerator is in a foreach block. It absolutely makes sense to have an enumerator be a struct to cover this case and see real benefit.

All this is is a case of having to do a little be of research to correctly use a feature a little bit outside of it's intended use-case. We all use enumerators outside of foreach blocks but I'm willing to bet that foreach or LINQ statements cover 99% of whatever real coding you do.