Q&A Categories
Find a Question:
C# for each
Answer this Question
You must be Logged In to post an Answer.
Not a member yet? Sign Up Now »
Star Points Scale
Earn points for Asking and Answering Questions!
[1 - 25
[26 - 50
[51 - 500
[501 - 5000
[5001 - 25000
[25001+
Answer #1
The only reason I can see to use foreach over for, is that the same bit of code can be written with a little less code than than the for loop.
With that being said, the compiler seems to be doing a little more work in the background than with the for loop.
It maybe worth your while to use a for loop instead of the foreach loop. The few less characters with the foreach loop may not be worth the seconds you saved while writing your code.