473,396 Members | 1,898 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

simple switch statement question

in vb6 you can do this:

select case value

case 1, 2
'do something

end case
how do you do this in c#?
thanks.
Nov 16 '05 #1
11 1252
You can do:

switch(fish)
{
case onefish:
case twofish:
case redfish:
DoSomething();
break;
case bluefish:
DoSomethingElse();
break;
}

--
Bob Powell [MVP]
Visual C#, System.Drawing

All you ever wanted to know about ListView custom drawing is in Well Formed.
http://www.bobpowell.net/currentissue.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*R SS*

The GDI+ FAQ: http://www.bobpowell.net/faqfeed.xml
Windows Forms Tips and Tricks: http://www.bobpowell.net/tipstricks.xml
Bob's Blog: http://royo.is-a-geek.com/siteFeeder...aspx?FeedId=41

*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*R SS*

"suzy" <su**@spam.com> wrote in message
news:DE****************@doctor.cableinet.net...
in vb6 you can do this:

select case value

case 1, 2
'do something

end case
how do you do this in c#?
thanks.

Nov 16 '05 #2
i know that, but what if i want to run the same bit of code for several
values of fish?
"Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message
news:OH**************@TK2MSFTNGP09.phx.gbl...
You can do:

switch(fish)
{
case onefish:
case twofish:
case redfish:
DoSomething();
break;
case bluefish:
DoSomethingElse();
break;
}

--
Bob Powell [MVP]
Visual C#, System.Drawing

All you ever wanted to know about ListView custom drawing is in Well Formed. http://www.bobpowell.net/currentissue.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*R SS*

The GDI+ FAQ: http://www.bobpowell.net/faqfeed.xml
Windows Forms Tips and Tricks: http://www.bobpowell.net/tipstricks.xml
Bob's Blog: http://royo.is-a-geek.com/siteFeeder...aspx?FeedId=41

*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*R SS*

"suzy" <su**@spam.com> wrote in message
news:DE****************@doctor.cableinet.net...
in vb6 you can do this:

select case value

case 1, 2
'do something

end case
how do you do this in c#?
thanks.


Nov 16 '05 #3
You need a break per case.

case onefish:
break;
case twofish:
break;
case redfish:
...

Bern

"Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message
news:OH**************@TK2MSFTNGP09.phx.gbl...
You can do:

switch(fish)
{
case onefish:
case twofish:
case redfish:
DoSomething();
break;
case bluefish:
DoSomethingElse();
break;
}

--
Bob Powell [MVP]
Visual C#, System.Drawing

All you ever wanted to know about ListView custom drawing is in Well Formed. http://www.bobpowell.net/currentissue.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*R SS*

The GDI+ FAQ: http://www.bobpowell.net/faqfeed.xml
Windows Forms Tips and Tricks: http://www.bobpowell.net/tipstricks.xml
Bob's Blog: http://royo.is-a-geek.com/siteFeeder...aspx?FeedId=41

*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*R SS*

"suzy" <su**@spam.com> wrote in message
news:DE****************@doctor.cableinet.net...
in vb6 you can do this:

select case value

case 1, 2
'do something

end case
how do you do this in c#?
thanks.


Nov 16 '05 #4
suzy wrote:
i know that, but what if i want to run the same bit of code for several
values of fish?
"Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message
news:OH**************@TK2MSFTNGP09.phx.gbl...
You can do:

switch(fish)
{
case onefish:
case twofish:
case redfish:
DoSomething();
break;
case bluefish:
DoSomethingElse();
break;
}

--
Bob Powell [MVP]


That's what Bob's code does! When fish is onefish, twofish, or
redfish, then DoSomething is called, when it is bluefish then
DoSomethingElse is called.

Maybe this will make it click:

switch (value)
{
case 1:
case 2:
DoSomething();
break;
}

This is what you asked using VB syntax.

Or maybe if you see it written this way:

switch(fish)
{
case onefish: case twofish: case redfish:
DoSomething();
break;
case bluefish:
DoSomethingElse();
break;
}

-glenn-
Nov 16 '05 #5
Bern Taylor wrote:
You need a break per case.

case onefish:
break;
case twofish:
break;
case redfish:
...

Bern
You can do:

switch(fish)
{
case onefish:
case twofish:
case redfish:
DoSomething();
break;
case bluefish:
DoSomethingElse();
break;
}

--
Bob Powell [MVP]


No you don't, Bern. Check the docs.

-glenn-
Nov 16 '05 #6
As per Bob's example, all three fishes call the same DoSomething:

case onefish:
case twofish:
case redfish:
DoSomething();
break;

Bern

"suzy" <su**@spam.com> wrote in message
news:N5****************@doctor.cableinet.net...
i know that, but what if i want to run the same bit of code for several
values of fish?
"Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message
news:OH**************@TK2MSFTNGP09.phx.gbl...
You can do:

switch(fish)
{
case onefish:
case twofish:
case redfish:
DoSomething();
break;
case bluefish:
DoSomethingElse();
break;
}

--
Bob Powell [MVP]
Visual C#, System.Drawing

All you ever wanted to know about ListView custom drawing is in Well

Formed.
http://www.bobpowell.net/currentissue.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*R SS*

The GDI+ FAQ: http://www.bobpowell.net/faqfeed.xml
Windows Forms Tips and Tricks: http://www.bobpowell.net/tipstricks.xml
Bob's Blog: http://royo.is-a-geek.com/siteFeeder...aspx?FeedId=41

*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*R SS*

"suzy" <su**@spam.com> wrote in message
news:DE****************@doctor.cableinet.net...
in vb6 you can do this:

select case value

case 1, 2
'do something

end case
how do you do this in c#?
thanks.



Nov 16 '05 #7
Missing ellipses!

case onefish:
...
break;

Bern

"-glenn-" <so*****@example.com> wrote in message
news:Om**************@TK2MSFTNGP10.phx.gbl...
Bern Taylor wrote:
You need a break per case.

case twofish:
break;
case redfish:
...

Bern
You can do:

switch(fish)
{
case onefish:
case twofish:
case redfish:
DoSomething();
break;
case bluefish:
DoSomethingElse();
break;
}

--
Bob Powell [MVP]


No you don't, Bern. Check the docs.

-glenn-

Nov 16 '05 #8
Bern Taylor wrote:
Missing ellipses!

case onefish:
...
break;


Nothing is missing. Please read the following, paying special attention
to the end.

http://msdn.microsoft.com/vcsharp/te...h/default.aspx
Nov 16 '05 #9
No, I left out elipses indicating where extra lines of code would be ....
"C# Learner" <cs****@learner.here> wrote in message
news:eN**************@tk2msftngp13.phx.gbl...
Bern Taylor wrote:
Missing ellipses!

case onefish:
...
break;


Nothing is missing. Please read the following, paying special attention
to the end.

http://msdn.microsoft.com/vcsharp/te...h/default.aspx

Nov 16 '05 #10
Per case a break else there will be a "fallthrough" syndrome where
control will fulfill all the cases until it encounters a "break
statement, ellipses or no ellipses!

with regards,
J.V.Ravichandran
- http://www.geocities.com/
jvravichandran
- http://www.411asp.net/func/search?
qry=Ravichandran+J.V.&cob=aspnetpro
- http://www.southasianoutlook.com
- http://www.MSDNAA.Net
- http://www.csharphelp.com
- http://www.poetry.com/Publications/
display.asp?ID=P3966388&BN=999&PN=2
- Or, just search on "J.V.Ravichandran"
at http://www.Google.com

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #11
Bern Taylor wrote:
No, I left out elipses indicating where extra lines of code would be ....


Please re-read the entire thread.

Thanks
Nov 16 '05 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Andreas Paasch | last post by:
I'm attempting to trigger things based on time. I have one shop that has opening hours, closing hours and lunch hours store as full hour values, integer, in MySQL. I retrieve them, based on...
27
by: Brian Sabbey | last post by:
Here is a first draft of a PEP for thunks. Please let me know what you think. If there is a positive response, I will create a real PEP. I made a patch that implements thunks as described here....
35
by: Thomas Matthews | last post by:
Hi, My son is writing a program to move a character. He is using the numbers on the keypad to indicate the direction of movement: 7 8 9 4 5 6 1 2 3 Each number has a direction except...
3
by: ChrisHadley | last post by:
My simple sortheap configuration question is: the sortheap parameter specifies the amount of memory used by agents for sorts. Is this value the total for all agents or for each? Sort heap...
3
by: pgraeve | last post by:
I am a convert from VB to C# so bear with me on this "conversion" question C# switch statement seems to be the closest relative to VB's Select Case. I used VB's Select Case statement liberally. ...
4
by: Shawnk | last post by:
This post is intended to verify that true value semantics DO NOT EXIST for the Enum class (relative to boolean operations). If this is true then (thus and therefore) you can not design state...
4
by: priyanka | last post by:
Hi there, I had a question. Is there any way of testing a string value in a switch statement. I have about 50 string values that can be in a string variable. I tried cheking them with the if...
121
by: jacob navia | last post by:
Hi guys I have written this small parser to print out the functions defined in a C file. This is an example of parsing in C, that I want to add to my tutorial. Comments (and bug reports) are...
2
by: porter | last post by:
Im guessing this is a really simple question. How do server-side includes work in c#? For example, I have a swtich statement and depending on its output, I want to include different files. I had...
4
by: amit.uttam | last post by:
Hey there, I have a simple question about python print statement. Take the following code snippet for example... 1 print "-#- executing: %s" % section, 2 tests =...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
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...
0
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...
0
Oralloy
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,...
0
jinu1996
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...
0
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 using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.