Re: recursive GetEnumerator()
- From: Jon Skeet [C# MVP] <skeet@xxxxxxxxx>
- Date: Mon, 25 Jun 2007 19:35:44 +0100
colin <colin.rowe1@xxxxxxxxxxxxxxxxxx> wrote:
thanks Jon, thats quite a usefully concise info about what ive been doing,
I think I at least understand fairly well whats going on at the code level
now.
the 'yield return expresion' does make for a bit of confusion over flow of
control at first.
Yes. It's a lot easier than implementing IEnumerator/IEnumerable
yourself though :)
I think I understand that movenext is like moving to the next statemnt in
the GetEnumerator function if yield is used, and current would be like
storing the state information of the functions stack.
Not quite. The context information is stored within a newly generated
type, but Current has to return the current element within the
enumerated data.
although I had assumed it just put the code inline or something,
and put the code inside the foreach block at each yeild statement.
No, it couldn't do that - don't forget that foreach could be in one
type, and the iterator in a completely different one.
Ive not tried using reflection or looking at the code directly,
im not sure I want to atm lol, I might not understand or like what I see.
There's a big difference between Reflector and reflection... if you
haven't used Reflector before, it's well worth downloading (just Google
for it).
maybe its not as fast as I would like if its actually storing the stack
info,
but then this isnt a method that will be used intensivly to access the list.
my original implementation was written partly in assembler many years ago
when CPU power wasnt so plentifull.
before that I also had a microcode version for a bit slice processor,
before content addressable ram made it obsolete.
Indeed - I wouldn't worry about speed until you've definitely got a
problem. It's not likely to be particularly slow, although using it
recursively can be a bit more of a hit than might be ideal:
http://blogs.msdn.com/toub/archive/2004/10/29/249858.aspx
--
Jon Skeet - <skeet@xxxxxxxxx>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
.
- 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
- Re: recursive GetEnumerator()
- From: Jon Skeet [C# MVP]
- Re: recursive GetEnumerator()
- From: colin
- Re: recursive GetEnumerator()
- From: Jon Skeet [C# MVP]
- Re: recursive GetEnumerator()
- From: colin
- recursive GetEnumerator()
- Prev by Date: Re: String.Format vs + operator
- Next by Date: Re: Missing .NET and Exceptions
- Previous by thread: Re: recursive GetEnumerator()
- Next by thread: Re: recursive GetEnumerator()
- Index(es):
Loading