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
George GeorgePosted May 2, 2008, 8:54 AM
Beyond the so-called pattern or something, any practical benefits we could have? For example, Flexibility? Performance? :-)
regards,
George
Santhosh VeeraramanPosted May 2, 2008, 6:22 AM
one reason could be, foreach is built on "iterator" pattern which is a proven solution for iterating jobs.
George GeorgePosted Apr 30, 2008, 9:17 AM
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
Blocked AccountPosted Apr 30, 2008, 6:19 AM
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!!