Re: Can someone explain why switch syntax is the way it is?
- From: "Jeremy Williams" <jeremydwill@xxxxxxxxxxxx>
- Date: Thu, 13 Oct 2005 09:56:25 -0500
"Scott Roberts" <scott.roberts@xxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:OX%23iVHA0FHA.460@xxxxxxxxxxxxxxxxxxxxxxx
>
> "Andrew Ducker" <andrew@xxxxxxxxxxxxx> wrote in message
> news:1129209462.752861.88480@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
>> And no, this isn't a complaint about break - I'm very happy to make
>> things explicit.
>>
>> However, why isn't the format something like:
>>
>> switch(myVariable)
>> {
>> case 1:
>> {
>> //Do Something
>> }
>> case 2:
>> {
>> //Do Something Else
>> }
>> default
>> // Do Nothing at all
>> }
>>
>> That way the 'break' is subsumed into the closing curly brackets, and
>> it follows the same way of grouping commands as the rest of the
>> language does.
>>
>> Andy D
>
> Well, it would certainly be more "C# like" that way, but it would prevent
> intentional "flow through" from one case to another. While I think such
> "flow through" is a horrible, horrible idea, I'm sure someone out there
> thinks it's absolutely necessary.
>
>
Since C# does not support the C++ style of "flow through" by leaving out the
break statement between cases (except when multiple cases pertain to the
exact same block of code), this is really not a big problem. Something like
this would work:
switch(val)
{
case 1:
case 2:
{
textBox1.Text = "Nothing";
}
case 3:
{
textBox1.Text = "Answer";
}
default:
{
}
}
I like it. It is definitely more consistent. Having this style as an
alternative format really does not seem to add any confusion - it is just as
clear what is being done.
.
- References:
- Re: Can someone explain why switch syntax is the way it is?
- From: Scott Roberts
- Re: Can someone explain why switch syntax is the way it is?
- Prev by Date: Re: Can someone explain why switch syntax is the way it is?
- Next by Date: Re: Can someone explain why switch syntax is the way it is?
- Previous by thread: Re: Can someone explain why switch syntax is the way it is?
- Next by thread: Re: Can someone explain why switch syntax is the way it is?
- Index(es):
Relevant Pages
|