Re: switch(true) in c#



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


.



Relevant Pages

  • Re: Performance of REGEXP_LIKE vs LIKE?
    ... There are certain situations where the syntax of REGEXP_LIKE ... is cleaner and shorter than the comparable LIKE expression. ... search of a 3 million record table, for a series of text strings. ... How about Oracle Text? ...
    (comp.databases.oracle.misc)
  • Re: Proposal for adding symbols within Python
    ... I don't like any syntax I've seen so far, but I can understand the problem. ... (Rather than a string used as a key in that namespace) ... Often you can use strings for that sort of thing, ... The reason I'm more interested in seeing usecases, ...
    (comp.lang.python)
  • Re: Array difference
    ... is there any logical reason why the language doesn't ... but they plan on having a syntax like this. ... use the initialization syntax for the String array. ... Which declares that the method accepts a variable number of strings. ...
    (comp.lang.java.programmer)
  • Re: Cantors definition of set
    ... Not the definition of ordered pair, ... at the level of distinguishing syntax from semantics. ... of set theory is strings of symbols, ... subsequent ones would be squares. ...
    (sci.logic)
  • The "Open" statement
    ... I'm struggling with the syntax of the open statement, the helpfile ... I know this makes me look thick but I've tried various things that have ...
    (microsoft.public.excel.misc)