troubleshooting Question

Create object in switch statement

Avatar of QPR
QPRFlag for New Zealand asked on
C#
5 Comments1 Solution336 ViewsLast Modified:
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.
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros