vendredi 6 novembre 2015

Parts of a nested if statement not being reached

I'm at a bit of a loss as to why the highestOrderLowestTradeVersion lines in this if-statement below are not being hit; when debugging, the aforementioned variable never exists in the if-statement context. Even if the final two if-statements below are true, it simply ignores the highestOrderLowestTradeVersion lines. I've tried moving the variable declaration higher in the list, not initialising it, and initialising it separately after declaring it, but I still can't get a value for that variable. Is there anything obviously wrong in my code below?

int latestOrderVersion;
int latestTradeVersion;

int lowestOrderVersion = 0;
int lowestOrderHighestTradeVersion = 0;

int highestOrderVersion = 0;
int highestOrderHighestTradeVersion = 0;
int highestOrderLowestTradeVersion = 0;

foreach (DataRow filterResult2 in filterResults2.Rows)
{
    latestOrderVersion = Convert.ToInt32(filterResult2["OrderVersion"]);
    latestTradeVersion = Convert.ToInt32(filterResult2["TradeVersion"]);

    if (lowestOrderVersion == 0 || latestOrderVersion < lowestOrderVersion)
    {
        lowestOrderVersion = latestOrderVersion;

        if (lowestOrderHighestTradeVersion == 0 || lowestOrderHighestTradeVersion < latestTradeVersion)
        {
            lowestOrderHighestTradeVersion = latestTradeVersion;
        }
    }


    if (highestOrderVersion == 0 || latestOrderVersion > highestOrderVersion || latestOrderVersion == highestOrderVersion)
    {
        if (latestOrderVersion != highestOrderVersion)
        {
            highestOrderVersion = latestOrderVersion;
            highestOrderLowestTradeVersion = 0;
        }

        if (highestOrderHighestTradeVersion == 0 || latestTradeVersion < highestOrderHighestTradeVersion)
        {
            highestOrderLowestTradeVersion = latestTradeVersion;
        }
    }
}

Aucun commentaire:

Enregistrer un commentaire