Re: [Feature Request] "first:" "last:" sections in a "foreach" block
From: Jon Skeet [C# MVP] (skeet_at_pobox.com)
Date: 04/05/04
- Next message: Amos: "changing datagrid column width"
- Previous message: Jon Skeet [C# MVP]: "RE: Random bytes on the beginning of encrypted file"
- In reply to: Dilip Krishnan: "Re: [Feature Request] "first:" "last:" sections in a "foreach" block"
- Next in thread: Joep: "Re: [Feature Request] "first:" "last:" sections in a "foreach" block"
- Reply: Joep: "Re: [Feature Request] "first:" "last:" sections in a "foreach" block"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 5 Apr 2004 20:09:31 +0100
Dilip Krishnan <dilipdotnet..NOSPAM..@apdiya.com> wrote:
> I would think that by the definition of foreach, the language construct
> is unable to predict the size of the enumerable in question. Which would
> mean that the foreach loop would need to read-ahead to determine the
> ordinality of the enumerable list. IMHO that would make the whole
> foreach inefficient would'nt you say?
You don't need to know the ordinality though - you only need to know
first or last. First is obvious, and the "last" bit you just execute
when the next MoveNext returns false (or whatever - I can't remember
the exact interface offhand). It would be slightly trickier to make the
"last" case not also execute "other", and it would be easier to
basically make that something executed *as well as* the "other" case,
but other than that it's not tricky.
-- Jon Skeet - <skeet@pobox.com> http://www.pobox.com/~skeet If replying to the group, please do not mail me too
- Next message: Amos: "changing datagrid column width"
- Previous message: Jon Skeet [C# MVP]: "RE: Random bytes on the beginning of encrypted file"
- In reply to: Dilip Krishnan: "Re: [Feature Request] "first:" "last:" sections in a "foreach" block"
- Next in thread: Joep: "Re: [Feature Request] "first:" "last:" sections in a "foreach" block"
- Reply: Joep: "Re: [Feature Request] "first:" "last:" sections in a "foreach" block"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|