469,271 Members | 895 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,271 developers. It's quick & easy.

switch case

In VB6 I could do the following

Select Case Right$(Text, 1)
Case "a","b"
do this
Case "c","d"
do this
Case else
do this
End Select
can I have multiple items per case in c#?

Thanks
Alan
Dec 19 '05 #1
3 36852
Alan,

Yes, but you would have to do it differently:

switch (Text.Substring(Text.Length - 1, 1))
{
case "a":
case "b":
// Do something

break;

case "c":
case "d":
// Do something else.

break;

default:

// Default case.
}

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Alan Roberts" <al**@statistixl.co.uk> wrote in message
news:uX**************@TK2MSFTNGP10.phx.gbl...
In VB6 I could do the following

Select Case Right$(Text, 1)
Case "a","b"
do this
Case "c","d"
do this
Case else
do this
End Select
can I have multiple items per case in c#?

Thanks
Alan

Dec 19 '05 #2
Thanks Nicholas. A bit more cumbersome but should do the trick!

Thanks again

Alan

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:u4**************@TK2MSFTNGP12.phx.gbl...
Alan,

Yes, but you would have to do it differently:

switch (Text.Substring(Text.Length - 1, 1))
{
case "a":
case "b":
// Do something

break;

case "c":
case "d":
// Do something else.

break;

default:

// Default case.
}

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Alan Roberts" <al**@statistixl.co.uk> wrote in message
news:uX**************@TK2MSFTNGP10.phx.gbl...
In VB6 I could do the following

Select Case Right$(Text, 1)
Case "a","b"
do this
Case "c","d"
do this
Case else
do this
End Select
can I have multiple items per case in c#?

Thanks
Alan


Dec 19 '05 #3
Alan Roberts <al**@statistixl.co.uk> wrote:
Thanks Nicholas. A bit more cumbersome but should do the trick!


Slightly less cumbersome would be to use the indexer instead of
Substring - this only works for a single character, however. (Note the
single quotes instead of double quotes):

switch (Text[Text.Length-1])
{
case 'a':
case 'b':
// Do something
break;
case 'c':
case 'd':
// Do something else.
break;
default:
// Default case.
}

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Dec 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

35 posts views Thread by Thomas Matthews | last post: by
10 posts views Thread by clueless_google | last post: by
7 posts views Thread by Colin King | last post: by
3 posts views Thread by pgraeve | last post: by
10 posts views Thread by Evie | last post: by
11 posts views Thread by ME | last post: by
6 posts views Thread by asit | last post: by
11 posts views Thread by =?Utf-8?B?anAybXNmdA==?= | last post: by
13 posts views Thread by Satya | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.