Skip to main content
1 of 2
nhgrif
  • 25.3k
  • 3
  • 63
  • 129
int position = -1;

foreach (string[] array in SearchKeys.Keys)
{
    position++;

This is extraordinarily suspect. In some languages, foreach or forin loops are faster than standard for loops. In others, they work out about the same. I'm pretty sure that in .NET, they're actually slower than regular for loops.

But with that said, foreach can sometimes improve readability, so they can still be nice to use. However, in this case, we're going to need a loop index anyways, so why don't we just write a regular for loop?

for (int position = 0; position < SearchKeys.Keys.Length; ++position)
nhgrif
  • 25.3k
  • 3
  • 63
  • 129