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.
Please take a look on some statistics here
ReplyDeletehttp://www.codeproject.com/KB/cs/foreach.aspx