Skip to main content

Which is fastest While, Do-While, Foreach

Foreach will be faster as it usually maintain no explicit counter, like while and do-while. Foreach essentially say "do this to everything in this set", rather than "do this x times". This will potentially avoid off-by-one errors and make code simpler to read.

Comments

  1. Please take a look on some statistics here

    http://www.codeproject.com/KB/cs/foreach.aspx

    ReplyDelete

Post a Comment