Re: recursive GetEnumerator()
- From: "Jon Skeet [C# MVP]" <skeet@xxxxxxxxx>
- Date: Mon, 25 Jun 2007 05:38:30 -0700
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
.
- Follow-Ups:
- Re: recursive GetEnumerator()
- From: colin
- Re: recursive GetEnumerator()
- References:
- recursive GetEnumerator()
- From: colin
- Re: recursive GetEnumerator()
- From: Göran Andersson
- Re: recursive GetEnumerator()
- From: colin
- Re: recursive GetEnumerator()
- From: Göran Andersson
- Re: recursive GetEnumerator()
- From: colin
- Re: recursive GetEnumerator()
- From: Jon Skeet [C# MVP]
- Re: recursive GetEnumerator()
- From: colin
- recursive GetEnumerator()
- Prev by Date: Re: ContainsKey() does not find key
- Next by Date: Re: Using ToString to pad an integer with leading zeroes
- Previous by thread: Re: recursive GetEnumerator()
- Next by thread: Re: recursive GetEnumerator()
- Index(es):