Re: recursive GetEnumerator()
- From: "Jon Skeet [C# MVP]" <skeet@xxxxxxxxx>
- Date: Mon, 25 Jun 2007 04:06:44 -0700
On Jun 25, 12:04 pm, "colin" <colin.ro...@xxxxxxxxxxxxxxxxxx> wrote:
Yes, it does return an enumerator. (Or, at least, it works as if it
returns an enumerator. I don't know exactly how it's implemented.)
it seems to actually return the data not the enumerator,
well it complains if you do,
I gues IEnumerator is just a sort of keyword to say its not a normal
function.
No, not at all. GetEnumerator returns an enumerator. That enumerator
is then used to fetch an IEnumerable, which has the MoveNext and
Current members.
foreach does all this for you under the hood.
im not sure what happens if you actually return data without yield,
wether it gets called for each element, I gues thats what the Next and
Current would be for.
yield return is just smart syntactic sugar which builds an IEnumerator/
IEnumerable.
You can use ildasm or reflector to see what types are in your compiled
code.
It's worth understanding what foreach does before you embark on C# 2's
iterator-building features.
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
- recursive GetEnumerator()
- Prev by Date: Re: A hypothetical competition
- Next by Date: Re: A hypothetical competition
- Previous by thread: Re: recursive GetEnumerator()
- Next by thread: Re: recursive GetEnumerator()
- Index(es):
Relevant Pages
|
Loading