Friday, September 10, 2010

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.

1 comment:

  1. Please take a look on some statistics here

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

    ReplyDelete