I've been unsuccessful finding a site that tells me, so I'm asking here:
can I have multiple 'clauses' per 'case' in a 'switch' statement?
e.g.
switch "myVar"
{
case "1", "a":
break;
case "2", "b":
break;
default:
break;
}
and if so, what's the proper syntax, as the above didn't work ;)
Many thanks 4 71849
string s = "b";
switch (s)
{
case "1":
case "a":
Console.WriteLine("s is 1 or a");
break;
case "2":
case "b":
Console.WriteLine("s is 2 or b");
break;
default:
break;
}
--
William Stacey [MVP]
"Kevin Blount" <ke**********@LOLgmail.comwrote in message
news:uF**************@TK2MSFTNGP04.phx.gbl...
| I've been unsuccessful finding a site that tells me, so I'm asking here:
|
| can I have multiple 'clauses' per 'case' in a 'switch' statement?
|
| e.g.
|
| switch "myVar"
| {
| case "1", "a":
| break;
| case "2", "b":
| break;
| default:
| break;
| }
|
| and if so, what's the proper syntax, as the above didn't work ;)
|
| Many thanks
Kevin Blount wrote:
I've been unsuccessful finding a site that tells me, so I'm asking here:
can I have multiple 'clauses' per 'case' in a 'switch' statement?
e.g.
switch "myVar"
{
case "1", "a":
break;
case "2", "b":
break;
default:
break;
}
and if so, what's the proper syntax, as the above didn't work ;)
Many thanks
switch "myVar"
{
case "1":
case "a":
break;
case "2":
case "b":
break;
default:
break;
}
Kevin,
can I have multiple 'clauses' per 'case' in a 'switch' statement?
Yes..
and if so, what's the proper syntax, as the above didn't work ;)
...the syntax is like this.
switch myVar
{
case "1":
case "a":
// your code here
break;
case "2":
case "b":
// your code here
break;
default:
// your code here
break;
}
Regards,
Richard
Thanks all for the help - just glad you all gave the same answer :)
Kevin
Richard Whitcher wrote:
Kevin,
>can I have multiple 'clauses' per 'case' in a 'switch' statement?
Yes..
>and if so, what's the proper syntax, as the above didn't work ;)
..the syntax is like this.
switch myVar
{
case "1":
case "a":
// your code here
break;
case "2":
case "b":
// your code here
break;
default:
// your code here
break;
}
Regards,
Richard
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: steve |
last post by:
I am quite frustrated with php’s include, as I have spent a ton of
time on it already... anyone can tell me why it was designed like this
(or something I don’t get)?
The path in include is...
|
by: Angelos |
last post by:
Ok... I have to make this administation area where I have multiple Contents
to add edit delete publish .
The problem is that I don't know what is the best way of making the forms.
At the moment I...
|
by: Juan |
last post by:
Thanks,
Juan.
|
by: Mike Hofer |
last post by:
While I'd toyed with C, C++, and Java over the last 20 years or so, my
principal language has been BASIC, QBASIC, then Visual Basic, and
finally Visual Basic .NET. But lately, I've been using C#...
|
by: Shapper |
last post by:
Hello,
I have a "Select Case MyVar" in which I define the values of an Array
according to the value of MyVar.
I need to use the Array Values in a Loop after End Select.
It seems the Array is...
|
by: Robbie Hatley |
last post by:
I'm getting a bizarre error with this code:
...
case WM_COMMAND:
{
switch (LOWORD(wParam)) // switch (control ID)
{
...
case IDC_RAIN_ENABLE_SIMPLE:
{
|
by: Robbie Hatley |
last post by:
Greetings, group. I just found a weird problem in a program where
a variable declared in a {block} after a "case" keyword was being
treated as having value 0 even though its actual value should...
|
by: thaytu888888 |
last post by:
Here is my codes in aspx page:
<td colspan="2" class="main_menu" runat="server" onclick='toggleDisplay(<%#Eval("description")%>);'><%#Eval("description")%></td>
Here is in "View source":
...
|
by: Adem |
last post by:
C/C++ language proposal:
Change the 'case expression' from "integral constant-expression" to "integral expression"
The C++ Standard (ISO/IEC 14882, Second edition, 2003-10-15)
says under...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |