Re: recursive GetEnumerator()



On Jun 25, 1:28 pm, "colin" <colin.ro...@xxxxxxxxxxxxxxxxxx> wrote:

<snip>

well im only using foreach on this tree to check the rest of it is working,
so I dont intend to make it too elaborate,
like i said before, the current and move next arnt very usefull in a tree,
unless the parent nodes are stored as well wich is messy.
with recursive calls they are stored but on the call stack.

Current and MoveNext() are the way that iterators work though - that's
the *only* way they work. There's no way of getting data out of a
plain IEnumerable/IEnumerable<T> without calling Current/MoveNext() at
the IL level - and that's exactly what foreach does.

I dont think I will be needing to use the iterator outside a foreach loop,
so I think im safe.

It's not a case of being safe or not - you're already using MoveNext()
and Current, and the enumerator that your code returns is implementing
MoveNext() and Current appropriately.

Jon

.