Re: Can someone explain why switch syntax is the way it is?



"Andrew Ducker" <andrew@xxxxxxxxxxxxx> schrieb im Newsbeitrag
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
>

An answer you can find on this site:
http://www.gotdotnet.com/team/csharp/learn/columns/ask.aspx#switch

The sentence that answers your question is at the end of the paragraph:
The reason this wasnt done was so that developers who were very used to C++
wouldnt have a hard time understanding what a switch statement was doing.

But I agree with you: Simply exiting a switch statement on reaching the end
of a case is much more usefull.

A good message:
This behavior could be added to C# without breaking existing programms. So,
if C#-Designers in future will agree with this, they could simply enhance C#
in that way.


.



Relevant Pages

  • Re: Can someone explain why switch syntax is the way it is?
    ... this isn't a complaint about break - I'm very happy to make ... > things explicit. ... why isn't the format something like: ... intentional "flow through" from one case to another. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Can someone explain why switch syntax is the way it is?
    ... this isn't a complaint about break - I'm very happy to make ... >> things explicit. ... > intentional "flow through" from one case to another. ... alternative format really does not seem to add any confusion - it is just as ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Can someone explain why switch syntax is the way it is?
    ... this isn't a complaint about break - I'm very happy to make ... >> things explicit. ... why isn't the format something like: ... > intentional "flow through" from one case to another. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Timezone
    ... write a switch statement do the time translation yourself.. ... but may work for you considering the thick of things you are in. ... current time in a format quite convenient for arithmetic, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: switch
    ... Alternatively you can format it like everyone else does: ... which is not much more verbose than the switch. ...
    (microsoft.public.dotnet.languages.csharp)

Loading