> Yes I've read your blog, that's what gave me the idea in the first
> place.. :)
:)
> Your enumerable is a good idea, but brings performance penalties with it.
Have you got a situation where those performance penalties are
significant?
In the case of my suggestion of an IEnumerable which just returned the
original IEnumerator, the performance penalty would be absolutely
*tiny*!
> One could also invent an operator which yields not the elements but the
> indices of a given collection, which also allows one to use the index
> within the foreach loop, which could also be used for determining the
> first and last element.
Do you mean like Enumerable.Range in .NET 3.5? (I'm working on a
generic Range class as part of my book, btw.)
> Making that GetIndexEnumerator() an extension method in C# 3 would be
> very nice. The more I thing about extension methods the more I love em.
[quoted text clipped - 4 lines]
> whatever). I mean, what is Reset() good for when you cannot use it,
> unless you do the loop manually, without using foreach?
If you really, really need the performance, just write the foreach
loop manually.
I suspect that it's *very* rare that the overhead introduced by
something like SmartEnumerable (or the other solution suggested here)
would be significant - definitely not common enough to be worth
requiring a language change.
(As for what Reset is good for - very little, IMO. It's often
unimplemented, and was probably a mistake in hindsight.)
Jon