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) ---------- Overall, the method could benefit greatly from some comments. You have none, and what you're doing isn't exactly simple or straight-forward. In the question, you're offering thanks to someone for helping you write it. If you required help writing it, then it's unlikely that you necessarily completely understand it. So if you later spot a bug, or you need to re-implement this in a slightly different way, are you going to understand all of this? Or if someone else is maintaining this, how much time do you want them to spend trying to figure out what the code does before they actually start improving it/fixing bugs/adding features/etc? Search algorithms should generally be well-commented, or provide a link to some commonly used algorithm (like a wiki page or something) which you've implemented (or attempted to implement).