-3

When I am writing code, I sometimes wonder which format is faster;

The old fashioned use of an incrementing variable: i

or

A foreach loop?

Paddy
  • 43
  • 3

2 Answers2

2

Neither is "faster" you need to use the right tool for the job, sometimes for is faster sometimes foreach is faster.

"micro optimizations" like you are taking about are so insignificant that you will NEVER recover the time in speed up than you will compared to the amount of extra time you took implementing it.

If your program is slow use a profiler on it and find where the real problem is.

Community
  • 1
  • 1
Scott Chamberlain
  • 116,967
  • 28
  • 260
  • 389