471,330 Members | 1,463 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

switch Case Question

Hi all,

Why this does'nt work:

switch(strExtenscao)
{
case ((".odo") || (".odo").ToUpper()):
//CODE
case ((".odb") || (".odb").ToUpper()):
//CODE
}

I will be gratful, probably is easy to solve. But I'm new with this language.

--
Thanks ,

Pedro
Dec 29 '05 #1
10 1137
switch(strExtenscao)
{
case ".odo":
case ".ODO":
//CODE
break;
case ".odb":
case ".ODB":
//CODE
break;
}

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
You can lead a fish to a bicycle,
but it takes a very long time,
and the bicycle has to *want* to change.

"Pedro" <Pe***@discussions.microsoft.com> wrote in message
news:60**********************************@microsof t.com...
Hi all,

Why this does'nt work:

switch(strExtenscao)
{
case ((".odo") || (".odo").ToUpper()):
//CODE
case ((".odb") || (".odb").ToUpper()):
//CODE
}

I will be gratful, probably is easy to solve. But I'm new with this
language.

--
Thanks ,

Pedro

Dec 29 '05 #2
Pedro <Pe***@discussions.microsoft.com> wrote:
Hi all,

Why this does'nt work:

switch(strExtenscao)
{
case ((".odo") || (".odo").ToUpper()):
//CODE
case ((".odb") || (".odb").ToUpper()):
//CODE
}

I will be gratful, probably is easy to solve. But I'm new with this
language.


The "cases" have to be constants. In this case, you could either write:

switch (strExtenscao)
{
case ".odo":
case ".ODO":
...
break;
case ".odb":
case ".ODB":
...
break;
}

or:

switch (strExtenscao.ToUpper())
{
case ".ODO":
...
break;
case ".ODB":
...
break;
}

Note that the latter version covers cases like ".odO" which the first
doesn't.

--
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 29 '05 #3
What about?

switch (strExtenscao.ToUpper())
{
case ".ODO":
...
break;
case ".ODB":
...
break;
}
Dec 29 '05 #4
Geat is work!

--
Thanks all,

Pedro
"D. Valdez" wrote:
What about?

switch (strExtenscao.ToUpper())
{
case ".ODO":
...
break;
case ".ODB":
...
break;
}

Dec 29 '05 #5
D. Valdez <dv*****@oslaw.com> wrote:
What about?

switch (strExtenscao.ToUpper())
{
case ".ODO":
...
break;
case ".ODB":
...
break;
}


Um, that's what I posted, isn't it?

--
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 29 '05 #6
Hi all,

Yours solutions was helpful.
--
Thanks ,

Pedro
"Jon Skeet [C# MVP]" wrote:
D. Valdez <dv*****@oslaw.com> wrote:
What about?

switch (strExtenscao.ToUpper())
{
case ".ODO":
...
break;
case ".ODB":
...
break;
}


Um, that's what I posted, isn't it?

--
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

Jan 2 '06 #7
On Thu, 29 Dec 2005 21:55:36 -0000, Jon Skeet [C# MVP]
<sk***@pobox.com> wrote:
D. Valdez <dv*****@oslaw.com> wrote:
What about?

switch (strExtenscao.ToUpper())
{
case ".ODO":
...
break;
case ".ODB":
...
break;
}


Um, that's what I posted, isn't it?


No. Your solution did not solve the problem of a mixed-case value. It
assumed the value would be only uppercase or lowercase.

Ken Wilson
Seeking viable employment in Victoria, BC
Jan 5 '06 #8

"Ken Wilson" <kw*********@NOshaw.SPAMca> wrote in message
news:lp********************************@4ax.com...
On Thu, 29 Dec 2005 21:55:36 -0000, Jon Skeet [C# MVP]
<sk***@pobox.com> wrote:
D. Valdez <dv*****@oslaw.com> wrote: <snip>Um, that's what I posted, isn't it?


No. Your solution did not solve the problem of a mixed-case value. It
assumed the value would be only uppercase or lowercase.

I suggest you re-read Jon's Post
************************************************** ****
The "cases" have to be constants. In this case, you could either write:

switch (strExtenscao)
{
case ".odo":
case ".ODO":
...
break;
case ".odb":
case ".ODB":
...
break;
}

or:

switch (strExtenscao.ToUpper())
{
case ".ODO":
...
break;
case ".ODB":
...
break;
}

Note that the latter version covers cases like ".odO" which the first
doesn't.
************************************************** ******

Looks like the second version covers it to me

Bill


Jan 5 '06 #9
Bill Butler <qw****@asdf.com> wrote:

<snip>
Looks like the second version covers it to me


In particular, the second version looks to me to be letter-for-letter
what D. Valdez posted :) (Even down to the indentation of the cases by
three characters instead of four...)

--
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
Jan 5 '06 #10
On Thu, 5 Jan 2006 03:57:52 -0000, Jon Skeet [C# MVP]
<sk***@pobox.com> wrote:
Bill Butler <qw****@asdf.com> wrote:

<snip>
Looks like the second version covers it to me


In particular, the second version looks to me to be letter-for-letter
what D. Valdez posted :) (Even down to the indentation of the cases by
three characters instead of four...)


My apologies Jon. I missed the second option that was part of your
post. You are, indeed, correct and take care of my concern for mixed
case.

Ken Wilson
Seeking viable employment in Victoria, BC
Jan 5 '06 #11

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

10 posts views Thread by Myster Ious | last post: by
6 posts views Thread by Aristotelis E. Charalampakis | last post: by
35 posts views Thread by Thomas Matthews | last post: by
19 posts views Thread by Christopher Benson-Manica | last post: by
3 posts views Thread by pgraeve | last post: by
11 posts views Thread by ME | last post: by

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.