Use foreach to Iterate the Loop of Integers
I have to change my programmatic approach. I'm speaking of iterating through int arrays. There are 3 ways:
- foreach iteration
- for loop
- for, caching the length of the array
ericgu says #1 and #2 are similar and #3 should be avoided. Strange, isn't it ? Because #3 is programmatically right. Also it was shown in one of .NET shows on MSDN that #3 is faster. It will be faster in some scripting languages like javascript. But it seems that #1 and #2 are optimized during compiling into JIT, and 3 may not be optimized.
Conclusion - use foreach because it is more readable in the code.
Monday, April 19, 2004 6:55 AM