C# 2.0 generic iterators
I was playing around with generic iterators in C# this morning. The 2.0 compiler does so much of the plumbing work for you that it's very easy to define a enumerable generic type. Your class doesn't even have to implement IEnumerable or IEnumerator - the compiler handles that under the covers for you. Your method just has to return IEnumerable. It's so much more succinct now. From my limited testing there doesn't seem to be much of a performance hit.... unless if you're thinking about using recursive iterators. Then you may want to be careful:
Recursive Iterators (aka Perf killers)
Technically this isn't specific to iterators, but its so much easier to do with iterators that I thought I'd mention it. Some languages are smart enough to 'flatten' iterators, such that if an iterator is called inside of another iterator, only one iteration object exists. C# is not one of those languages (at least not yet). Generally if you see any sort of recursion inside an iterator, you're asking for performance problems, simply because each time it recurses, it's going to create a whole new iteration object on the GC heap.