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)