473,378 Members | 1,555 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,378 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 1185
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Myster Ious | last post by:
Polymorphism replaces switch statements, making the code more compact/readable/maintainable/OO whatever, fine! What I understand, that needs to be done at the programming level, is this: a...
6
by: Aristotelis E. Charalampakis | last post by:
Hi all, this is a newbie question :-) I was wondering if there was a way to use the switch statement in a manner that each case statement includes more that a simple value. i.e.: switch (...
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...
19
by: Christopher Benson-Manica | last post by:
On a note related to my question about logical XOR, I'm trying to think of a non-obfuscated way to condense the following code block (which, as usual, I did not write): switch( int_val_1 ) {...
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. ...
11
by: ME | last post by:
In C# the following code generates a compiler error ("A constant value is expected"): public void Test(string value) { switch (value) { case SimpleEnum.One.ToString(): MessageBox.Show("Test...
10
by: anon.asdf | last post by:
Here's a reminder of duff's device: /*************************************/ #include <stdio.h> #define STEP 8 #define MAX_LEN STEP*4+1 #define SOURCE_LEN 28
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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?
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...

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.