A simple string array Iteration in C# .NET doesn't work

Posted by met.lord on Stack Overflow See other posts from Stack Overflow or by met.lord
Published on 2011-01-05T20:34:09Z Indexed on 2011/01/05 20:53 UTC
Read the original article Hit count: 210

This is a simple code that should return true or false after comparing each element in a String array with a Session Variable. The thing is that even when the string array named 'plans' gets the right attributes, inside the foreach it keeps iterating only over the first element, so if the Session Variable matches other element different than the first one in the array it never returns true... You could say the problem is right there in the foreach cicle, but I cant see it... I've done this like a hundred times and I can't understand what am I doing wrong... Thank you

protected bool ValidatePlans()
{
    bool authorized = false;

    if (RequiredPlans.Length > 0)
    {
        string[] plans = RequiredPlans.Split(',');
        foreach (string plan in plans)
        {
            if (MySessionInfo.Plan == plan)
                authorized = true;
        }
    }
    return authorized;
}

© Stack Overflow or respective owner

Related posts about c#

Related posts about string