Link to home
Start Free TrialLog in
Avatar of Paul Kahl
Paul KahlFlag for United States of America

asked on

using an Array in a Switch Statement

I have this code:
        string strSessionPageID = Session["SessionPageID"].ToString();

        switch (strSessionPageID)
        {
            case "3":
                //do x
                break;
            case "5":
                //do y
                break;
        }

what I'd like to be able to do is set up arrays, and use the switch like this:

        string strSessionPageID = Session["SessionPageID"].ToString();

        array xArr = array("3","43","56","68");
        array yArr = array("34","42","51","63");

        switch (strSessionPageID)
        {
            case xArr:
                //do x
                break;
            case yArr:
                //do y
                break;
        }

where I use the ID in the switch, and check it against the arrays to determine the case to perform.

Is there a way to do this, and if so, might I have an example?
ASKER CERTIFIED SOLUTION
Avatar of Expert1701
Expert1701

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Paul Kahl

ASKER

That looks like it will work fantastically well. Thank you very much.