Hello everyone,
Two questions,
1.
How foreach utilizes the IEnumerator interface and IEnumerable interface? Any there any docuements? I am interested in it.
2.
Pros and cons compared with using foreach and using simple index variable to iterate? Like,
[Code]
for (int i = 0; i < abc.Count; i++)
{
// access abc [i] here
}
[/Code]
thanks in advance,
George

Blocked AccountRank #403 · 6.2K reputationPosted Apr 30, 2008, 2:19 AM EDT
Basically Foreach is used for the collection and
foreachcopies the current array to a new one for the operation. Whilefordoesn't care of that part.Happy Coding!!
George GeorgeRank #1,736 · 870 reputationPosted Apr 30, 2008, 5:17 AM EDT
Thanks Manish,
I am interested in this topic. What advantage could we have in foreach? I think making a copy is slower... why CLR does so?
regards,
George
Santhosh VeeraramanRank #1,369 · 1.2K reputationPosted May 2, 2008, 2:22 AM EDT
one reason could be, foreach is built on "iterator" pattern which is a proven solution for iterating jobs.
George GeorgeRank #1,736 · 870 reputationPosted May 2, 2008, 4:54 AM EDT
Beyond the so-called pattern or something, any practical benefits we could have? For example, Flexibility? Performance? :-)
regards,
George