Solved

switch statement

Posted on 2009-07-15
5
177 Views
Last Modified: 2013-12-17
Can I use different constant-statement in one single case?

for example:

switch (strCountry)

case "UNITED STATES" || "USA" || "US" ||   "MX" ||   "MEXICO" ||"MEX" ||"CANADA" || "CA":
{
do things...
}

case "SPAIN" || "FRANCE" || "GERMANY" :
{
do things...
}


obviously this doesnt work , but i was wondering if exists another way to do it because i have a lot of values for strCountry and i wanted to avoid  a lot of IF statements.
0
Comment
Question by:Veljean
  • 3
5 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 125 total points
ID: 24862300
this should do:
switch (strCountry)
{
  case "UNITED STATES":
  case "USA": 
  case "US":
  case "MX":
  case "MEXICO":
  case "MEX":
  case "CANADA":
  case "CA":
    do things...
    break; 
  case "SPAIN":
  case "FRANCE":
  case "GERMANY" :
    do things...
    break;
}

Open in new window

0
 
LVL 22

Expert Comment

by:p_davis
ID: 24862316
you can just

case "US":
case "MX":

down untill you have all of your options then at then end put what you want to happen and the break;
0
 
LVL 22

Expert Comment

by:p_davis
ID: 24862319
grrr
0
 
LVL 1

Author Comment

by:Veljean
ID: 24862334
thank you guys! but angelll was first :p
0
 
LVL 22

Expert Comment

by:p_davis
ID: 24862340
angel is always first =)
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Contant UI messages in .NET 1 41
Windows Management Instrument 6 59
.net VBA word safemode 1 24
Need to Modify a Script I found 5 77
Normally the drop down box control found in the .Net framework tools is able to select just one data and value at a time, which is displayed on the text area.   But what if you want to have multiple values to be selected in the drop down box? As …
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now