from ScaleNet.pdf
Page 251-252
Chapter5: Improving Managed Code Performance ( Collection Guidelines )
Consider for Instead of foreach
Use for instead of foreach (C#) to iterate the contents of arrays or
collections in
performance critical code, particularly if you do not need the protections
offered by
foreach.
Both foreach in C# and For Each in Visual Basic .NET use an enumerator to
provide
enhanced navigation through arrays and collections. As discussed earlier,
typical
implementations of enumerators, such as those provided by the .NET
Framework,
will have managed heap and virtual function overhead associated with their
use.
If you can use the for statement to iterate over your collection, consider
doing so in
performance sensitive code to avoid that overhead.
Just one question? The enumerator discussed in above para .. is it the same
as IEnumerable.GetEnumerator. Because then foreach must be the most slowest
option as in the same section of the document it has one section named
"Consider Enumerating Overhead."
Sorry didnt read it first b4 posting.
HTH
rawCoder
"rawCoder" <ra******@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Hi,
Which is better in terms of performance.
Iterating over Enumerator
ForNext loop (using indexer)
ForEach loop
Thanx
rawCoder