Also you are aloud to transfer control from from case block to another (which gives the same functionality as fall-through, but in an obviously inteded way rather than happning by accident.
switch(i)
{
case 0:
case 1:
// do some stuff
goto case 2;
case 2:
// do some other stuff
break;
}
Regards
Richard Blewett - DevelopMentor
http://staff.develop.com/richardb/weblog
nntp://news.microsoft.com/microsoft.public.dotnet.languages.csharp/<uL0rv2rrEHA.3488@TK2MSFTNGP11.phx.gbl>
From MSDN:
Although fall through from one case label to another is not supported, it is
allowed to stack case labels, for example:
case 0:
case 1:
// do something;
Eran Kampf
http://www.ekampf.com
"JuLiE Dxer" <MsJuLiE@verizon.net> wrote in message
news:ub4im0dl7ckq8ofju6sd5e57aiq4dme9cs@4ax.com...[color=blue]
>I thought fall-throughs in switch statements were not supported in C#
> (design choice).
>
> At least, that's what mentioned on page 224 of Microsoft's "Inside C#"
> by Tom Archer
>
> On Sat, 09 Oct 2004 17:32:29 GMT, "Michael C" <michaelc@nospam.org>
> wrote:
>[color=green]
>>Hi Chris,
>>
>>We were discussing the heck out of that a few months ago, and the answer
>>is
>>(in C#), no. On the other hand, if you only have two ranges as in the
>>example you posted, an if...else construct would be almost as efficient.
>>If
>>you have only a couple of options per case statement, case can
>>drop-through
>>like this:
>>
>>switch (i)
>>{
>> case 100:
>> case 101:
>> // do something
>> break;
>> case 1000:
>> case 1001:
>> case 1002:
>> // do something else
>> break;
>>}
>>
>>Thanks,
>>Michael C., MCDBA
>>
>>"Chris" <christianc@pandora.be> wrote in message
>>news:o2V9d.273844$rh2.14058566@phobos.telenet-ops.be...[color=darkred]
>>> Hi,
>>>
>>> can you specify a range in a switch - statement ?
>>>
>>> switch (i)
>>> {
>>> case 100 - 999 :
>>> // do something
>>> break;
>>> case 1000 - 9999:
>>> // do something else
>>> break;
>>> }
>>>
>>> Previous syntax is not allowed, I know,
>>> but can you solve this using 'switch' ? without having to provide a case
>>> statement for every possible value and without using 'if' ?
>>>
>>> thanks
>>> Christian
>>>
>>>
>>>[/color]
>>[/color]
>[/color]
---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (
http://www.grisoft.com).
Version: 6.0.771 / Virus Database: 518 - Release Date: 28/09/2004
[microsoft.public.dotnet.languages.csharp]