473,396 Members | 1,989 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.

switch statement expressions

Is there a way in c# to have a switch statement with multiple expressions
like in VB.net?

Select Case e.Item.ItemType
Case ListItemType.Item, ListItemType.AlternatingItem,
ListItemType.EditItem
[code]
Case expression, expression2
[code]
End Select
Nov 18 '05 #1
3 2147
*doh*

case espression1:
case expression2:
[code]
break;
case expression3:
[code]
break;

"John" <jh******@msn.com> wrote in message
news:Ox**************@TK2MSFTNGP12.phx.gbl...
Is there a way in c# to have a switch statement with multiple expressions
like in VB.net?

Select Case e.Item.ItemType
Case ListItemType.Item, ListItemType.AlternatingItem,
ListItemType.EditItem
[code]
Case expression, expression2
[code]
End Select

Nov 18 '05 #2
int x;
.....
switch (x)
{
case 0:
case 1:
{
...
}
default:
{
}
}

see
http://msdn.microsoft.com/library/de...hstatement.asp
for full details

cheers

Simon

"John" <jh******@msn.com> wrote in message
news:Ox**************@TK2MSFTNGP12.phx.gbl...
Is there a way in c# to have a switch statement with multiple expressions
like in VB.net?

Select Case e.Item.ItemType
Case ListItemType.Item, ListItemType.AlternatingItem,
ListItemType.EditItem
[code]
Case expression, expression2
[code]
End Select

Nov 18 '05 #3
Hi,

There are a number of ways you can achieve the same flow.

Switch( e.item.itemType )
{
case ListItemType.Item:
case ListItemType.AlternatingItem:
case ListItemType.EditItem:
[code]
break;
case ListItemType.SelectedItem:
[code]
break;
case ListItemType.Header:
case ListItemType.Footer:
[code]
break;
default:
[default catch all code if required]
break;
}

Alternativly you might want to jump from one case to another for example

Switch( e.item.itemType )
{
case ListItemType.Item:
[code]
break;
case ListItemType.AlternatingItem:
[code]
goto case ListItemType.Item;
case ListItemType.EditItem:
[code]
break;
case ListItemType.SelectedItem:
[code]
goto case ListItemType.EditItem;
default:
[default catch all code if required]
break;
}

Here the item will contain code for items. The AlternatingItem will contain code for the alternating item such as a colour then jump to the Item case statement before exiting the switch. Obviously you have to think about the code you are adding i.e. if you set the colour in the AlternatingItem and then call Item where it sets the default colour this will replace the one set in the AlternatingItem. Ultimatly you would not set the colour here as the control has the relevant properties but this just demonstrates two possible methods

- Mike

---------------------------------------------------------------------------------
<a href="http://www.cogitar.net"> Cogitar Software. (www.cogitar.net) </a>
http://www.web-dominion.co.uk Web-Dominion. (Web Design and hosting )
---------------------------------------------------------------------------------

"John" <jh******@msn.com> wrote in message news:Ox**************@TK2MSFTNGP12.phx.gbl...
Is there a way in c# to have a switch statement with multiple expressions
like in VB.net?

Select Case e.Item.ItemType
Case ListItemType.Item, ListItemType.AlternatingItem,
ListItemType.EditItem
[code]
Case expression, expression2
[code]
End Select

Nov 18 '05 #4

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

Similar topics

14
by: Rudi Hansen | last post by:
I dont seem to be able to find the switch statement in Python. I would like to be able to do switch(var) case 1 : print "var = 1" case 2: print "var = 2"
2
by: Skip Montanaro | last post by:
Stephen> { Stephen> 'one': lambda x:x.blat(), Stephen> 'two': lambda x:x.blah(), Stephen> }.get(someValue, lambda x:0)(someOtherValue) One thing to remember is that function calls in Python...
15
by: Mike and Jo | last post by:
I've been converting some code to C++. I'm trying to use the Switch function to compare a result. Is it possible to use switch to evaluate '>0', '<0', 0? Example switch (result) { case...
1
by: Mike Berger | last post by:
I'm trying to do the following switch statement switch i { case '> 1': break; case '=1': break; case '<1': break; }
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...
21
by: Andy | last post by:
Can someone tell me if the following Switch...Case construct is valid? I'm wanting to check for multiple values in the Case statement without explicitly listing each values. So for example, will...
6
by: Mark Broadbent | last post by:
How on earth did Anders & co arrive at this awful switch/ case/ select statement? Not only does it lose the abilty to do an intelligent switch a-la VB eg. using >, <, list of values etc .... but...
13
by: jsta43catrocks | last post by:
In C++, my "switch" statement is okay when I ask it do evaluate ONE expression. (My number that I'm evaluating is one of ten single digits; I have ten cases for the ten digits.) BUT, I have five...
2
by: jalqadir | last post by:
In my program I have the following statements void Person::setTitle(const Glib::ustring& str) { switch ( str ) { case "None" : { title = title_t::None; break; } case "Dr" : { title =...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
tracyyun
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 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.