switch Case Question

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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.
 
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 said:
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.
 
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
 
Ken Wilson said:
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
 
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...)
 
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
 
Back
Top