Results.
Foreach version required slightly more time to execute than the for version. This is because the foreach-version uses more local variable space.
I strongly recommend everyone to use
for
loop rather than foreach
at any stage.Plus for "foreach"
Using a
foreach
loop demonstrates to anyone using your code
that you are planning to do something to each member of a collection
irrespective of its place in the collection. It also shows you aren't
modifying the original collection (and throws an exception if you try
to). http://www.codeproject.com/Articles/6759/FOREACH-Vs-FOR-C
http://www.dotnetperls.com/for-foreach
http://www.david-amador.com/2009/12/csharp-foreach-vs-for-loop/
http://www.codekicks.com/2011/01/try-to-avoid-foreachfor-loops.html
Brak komentarzy:
Prześlij komentarz