[Solved] New version of doing a for loop?


I don’t think this loop is a good candidate for a foreach loop. If you were to do so, it would look something like this:

var codeLengths = new[] { 4, 3, 2, 1 };
foreach (length in codeLengths)
{
    if(xmlGenioCodes.SelectSingleNode(String.Format("GenioCodes[Code =\"{0}\"]", strCodeMX.Substring(0, length))) != null)
    {
        strCodeMXLayer = strCodeMX.Substring(0, length);
        break;
    }
}

EDIT

Per the request in your question, here is a link where you can find more information about C#’s foreach language feature.

4

solved New version of doing a for loop?