Michael C wrote:
"Göran Andersson" <gu***@guffa.comwrote in message
news:Oj**************@TK2MSFTNGP05.phx.gbl...
>An Enumerator is an iterator.
Here, the C# example of an iterator uses an Enumerator:
http://en.wikipedia.org/wiki/Iterator
When you are talking about differences between an Iterator and an
Enumerator, you are talking about differences in specific
I think I get it, what they call an iterator is just a shortcut to avoid
creating your IEnumerator class.
Actually an enumerator is generally a struct, not a class. Typically it
uses 16 bytes of stack space, which definitely isn't much to whine about.
Basically the article was wrong in saying
it will save a lot of memory.
It might be correct for a specific implementation of an enumerator, but
not for enumerators in general.
>implementations of iterators. For this discussion to go anywhere, you have
to specify what exact implementations you are talking about.
The article didn't specify an particular implementation, it was just a fake
class with no code given, something like this:
foreach(Entry e in PhoneBook.GetNumbersFor("New York"))
{
}
The GetNumbersFor method was not provided.
If the GetNumbersFor method would create a collection, the foreach
statement will create an enumerator for that collection. The enumerator
for a collection of course requires that the collection is present in
memory, but that requirement is only for that specific implementation of
an enumerator, not all enumerators.
--
Göran Andersson
_____
http://www.guffa.com