RE: switch(true) in c#

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



None of your respondants are empathetic. Much as I disliked VB, the "select
case true" construct rocks. It is especially useful for filtering out error
conditions. Don't know of any equivalent.
Concerning help, I always use the online reference; it's always up to date.
Here's the link for C#: http://tinyurl.com/sb48

"Frank" wrote:

> 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