Avatar of QPR
QPR
Flag for New Zealand asked on

Create object in switch statement

Based on a case I need to call a given web service reference.
I'm having trouble working out how to create an object from a given type based on this.
If I try to create it in each case then I get that the local variable "client" already exists in this scope.
Another error is that when I refer to "client" outside of the switch it says it does not exist.

switch (appType)
            {
                case "bcapps":
                    ListName = "";
                    A_BC_WS_Lists.Lists client = new A_BC_WS_Lists.Lists();
                    break;
                case "ehlthapps":
                    ListName = "";
                    B_BC_WS_Lists.Lists client = new B_BC_WS_Lists.Lists();
                    break;
                case "luc":
                    ListName = "";
                    break;
                case "Sub":
                    ListName = "";
                    break;
            }

How can I dynamically create the object based on the value of the case.
How can I refer to this if it is created within the switch.
C#

Avatar of undefined
Last Comment
QPR

8/22/2022 - Mon
kaufmed

Do the classes share a common base class, or might they implement any common interfaces? Did you create these classes yourself, or were they auto-generated for you?
QPR

ASKER
They are web service references (to call a web service)
So based on the value of a variable I need to create client like this

A_BC_WS_Lists.Lists client = new A_BC_WS_Lists.Lists();

The image shows my list of web service refs

refs
ASKER CERTIFIED SOLUTION
kaufmed

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
QPR

ASKER
Thanks ill digest and test this when back at work tomorrow
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
QPR

ASKER
Thanks