A simple string array Iteration in C# .NET doesn't work
- by met.lord
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;
}