Re: switch(true) in c#
- From: "Alvin Bruney [Microsoft MVP]" <www.lulu.com/owc>
- Date: Thu, 4 Aug 2005 11:44:26 -0400
switch statements evaluate strings, they don't work on boolean variables.
have a look at the syntax for it in the helpfile and work your code
accordingly
--
Regards
Alvin Bruney
[Shameless Author Plug]
The Microsoft Office Web Components Black Book with .NET
available at www.lulu.com/owc, Amazon, B&H etc
-------------------------------------------------------------------------------
"Frank" <frank.favinger@goooooogle's e-mail domain> wrote in message
news:U7GdnVQEnqK4qm_fRVn-tA@xxxxxxxxxxxxxxx
> Hi,
>
> In classic ASP with vbscript, I'd sometimes do this.
>
> Select case true
> case x = 3
> code
> case y = 6
> code
> case r = "tick"
> code
> End select
>
> In C#, is there a way of doing such a thing? The current code I have that
> is /not/ valid is this.
>
> switch(true) {
> case sPN!="":
> something();
> break;
> case sPF!="":
> //something else
> break;
> default:
> //do something different
> break;
> }
>
> I know that I could do a few nested ifs, but if there are 10 different
> unrelated conditions I want to test for, it could get kinda messy.
>
> Thanks,
>
> Frank
>
>
.
- Follow-Ups:
- Re: switch(true) in c#
- From: Frank
- Re: switch(true) in c#
- References:
- switch(true) in c#
- From: Frank
- switch(true) in c#
- Prev by Date: switch(true) in c#
- Next by Date: Close Form/Webpage and hyperlink back to Original Page
- Previous by thread: switch(true) in c#
- Next by thread: Re: switch(true) in c#
- Index(es):
Relevant Pages
|