Connecting Tech Pros Worldwide Forums | Help | Site Map

C# Switch statement

Duncan McNutt [BSDM]
Guest
 
Posts: n/a
#1: Nov 15 '05
Is it possible to have ranges or patterns in a case ?

If not, why wasnt this designed in to make it easier instead of listing
every case value needed?

--

Duncan McNutt
Microsoft Product Deactivation Team
--





Harry Bosch
Guest
 
Posts: n/a
#2: Nov 15 '05

re: C# Switch statement


"Duncan McNutt [BSDM]" <nutmaster@127.0.0.66> wrote:
[color=blue]
> Is it possible to have ranges or patterns in a case ?
>
> If not, why wasnt this designed in to make it easier instead of listing
> every case value needed?[/color]

You should get a beginner's C# book and start reading it.

--
harry
Duncan McNutt .[BSDM]
Guest
 
Posts: n/a
#3: Nov 15 '05

re: C# Switch statement


I am trying to install MIS 2002 Trial I downloaded from the MS site but I
get the following errors.

How can I fix this and get it installing? Any ideas?

Event Type: Error
Event Source: MsiInstaller
Event Category: None
Event ID: 11720
Date: 8/17/2003
Time: 10:09:38 PM
User: N/A
Computer: VMWARE2KPRO
Description:
Product: Mobile Information Server -- Error 1720.There is a problem with
this Windows Installer package. A script required for this install to
complete could not be run. Contact your support personnel or package vendor.
Custom action IsDCLogon script error -2147023665, : Line 2339, Column 5,

--

Duncan McNutt
Microsoft Product Deactivation Team
--



"Harry Bosch" <none@given.com> wrote in message
news:Xns93DA899A21702hboschsbc@207.46.248.16...[color=blue]
> "Duncan McNutt [BSDM]" <nutmaster@127.0.0.66> wrote:
>[color=green]
> > Is it possible to have ranges or patterns in a case ?
> >
> > If not, why wasnt this designed in to make it easier instead of listing
> > every case value needed?[/color]
>
> You should get a beginner's C# book and start reading it.
>
> --
> harry[/color]


Duncan McNutt .[BSDM]
Guest
 
Posts: n/a
#4: Nov 15 '05

re: C# Switch statement


oops, wrong thread.

--

Duncan McNutt
Microsoft Product Deactivation Team
--



"Duncan McNutt .[BSDM]" <mutmaster@127.0.0.22> wrote in message
news:uhr1Y7PZDHA.388@TK2MSFTNGP10.phx.gbl...[color=blue]
> I am trying to install MIS 2002 Trial I downloaded from the MS site but I
> get the following errors.
>
> How can I fix this and get it installing? Any ideas?
>
> Event Type: Error
> Event Source: MsiInstaller
> Event Category: None
> Event ID: 11720
> Date: 8/17/2003
> Time: 10:09:38 PM
> User: N/A
> Computer: VMWARE2KPRO
> Description:
> Product: Mobile Information Server -- Error 1720.There is a problem with
> this Windows Installer package. A script required for this install to
> complete could not be run. Contact your support personnel or package[/color]
vendor.[color=blue]
> Custom action IsDCLogon script error -2147023665, : Line 2339, Column 5,
>
> --
>
> Duncan McNutt
> Microsoft Product Deactivation Team
> --
>
>
>
> "Harry Bosch" <none@given.com> wrote in message
> news:Xns93DA899A21702hboschsbc@207.46.248.16...[color=green]
> > "Duncan McNutt [BSDM]" <nutmaster@127.0.0.66> wrote:
> >[color=darkred]
> > > Is it possible to have ranges or patterns in a case ?
> > >
> > > If not, why wasnt this designed in to make it easier instead of[/color][/color][/color]
listing[color=blue][color=green][color=darkred]
> > > every case value needed?[/color]
> >
> > You should get a beginner's C# book and start reading it.
> >
> > --
> > harry[/color]
>
>[/color]


Stan
Guest
 
Posts: n/a
#5: Nov 15 '05

re: C# Switch statement


Here, I did a search and copied one of the many replies to this common
question.[color=blue]
>[/color]

Yes, like this:

using System;

class Test
{

public static void Main()
{
int x;
x=Convert.ToInt16(Console.ReadLine());
switch (x)
{
case 1:
case 2:
case 3:
Console.WriteLine("Is 1 2 3");
break;
case 4:
case 5:
case 6:
Console.WriteLine("Is 4 5 6");
break;
default:
Console.WriteLine("Is greater than 6");
break;
}
}
}

However, you can't do greater than/less than (i.e. case 4 to 6) like
you could do in VB. You'll have to use if/else statements for that.

'Lib



"Duncan McNutt [BSDM]" <nutmaster@127.0.0.66> wrote in message
news:eNPUQtPZDHA.2352@TK2MSFTNGP12.phx.gbl...[color=blue]
> Is it possible to have ranges or patterns in a case ?
>
> If not, why wasnt this designed in to make it easier instead of listing
> every case value needed?
>
> --
>
> Duncan McNutt
> Microsoft Product Deactivation Team
> --
>
>
>
>[/color]


Michael A. Covington
Guest
 
Posts: n/a
#6: Nov 15 '05

re: C# Switch statement



"Frank Eller [MVP]" <webmaster@frankeller.de> wrote in message
news:%23G0$M7PZDHA.1872@TK2MSFTNGP12.phx.gbl...
[color=blue][color=green]
> > If not, why wasnt this designed in to make it easier instead of listing
> > every case value needed?[/color]
>
> ... here you will have to ask the c# design team.[/color]

I think they followed C too closely. C, in turn, was designed to be easy to
compile.


Edward Yang
Guest
 
Posts: n/a
#7: Nov 15 '05

re: C# Switch statement


I love C#. But I strongly disagree with M$ C# team on the design of the
switch-break statement.

C# does not allow automatic fall through for each case statement, yet it
requires a mandatory and useless break statement. It's completely insane to
have such a design. The break statement is compeletely NOT NECESSARY!

I understand they want to make programmers make LESS errors by breaking
C/C++ goodness (e.g., range of values). But those errors caused by
case-break pair never get in my way throughout 8 years of C/C++ programming
experience. Actually I've never made a mistake when coding case-break's.

I think they might want to give a compiler warning when there is no break
statement after a case statement. That's the best way keeping C/C++ goodness
yet giving programmers much, much less chance for making errors.

Edward


"Duncan McNutt [BSDM]" <nutmaster@127.0.0.66> wrote in message
news:eNPUQtPZDHA.2352@TK2MSFTNGP12.phx.gbl...[color=blue]
> Is it possible to have ranges or patterns in a case ?
>
> If not, why wasnt this designed in to make it easier instead of listing
> every case value needed?
>
> --
>
> Duncan McNutt
> Microsoft Product Deactivation Team
> --
>
>
>
>[/color]


Edward Yang
Guest
 
Posts: n/a
#8: Nov 15 '05

re: C# Switch statement



"Frank Eller [MVP]" <webmaster@frankeller.de> wrote in message
news:%23G0$M7PZDHA.1872@TK2MSFTNGP12.phx.gbl...[color=blue]
> Hi Duncan,
>[color=green]
> > Is it possible to have ranges or patterns in a case ?[/color]
>
> No.
>[/color]

It is a half yes. See Stan's reply in this thread.
[color=blue]
>[color=green]
> > If not, why wasnt this designed in to make it easier instead of listing
> > every case value needed?[/color]
>
> ... here you will have to ask the c# design team.
>
> Regards,
>
> --
> Frank Eller [.NET MVP]
> www.frankeller.de
> .NET Developers Group Munich- www.munichdot.net
>
>[/color]


Harry Bosch
Guest
 
Posts: n/a
#9: Nov 15 '05

re: C# Switch statement


"Michael A. Covington" <Michael@CovingtonInnovations.com> wrote:
[color=blue]
> I think they followed C too closely. C, in turn, was designed to be
> easy to compile.[/color]

It's also because a 'switch' can be optimized a lot better. You are
checking a single value against a series of constants, and code can be
generated to do that which is faster than the code for the corresponding
'if' statements. For instance, the value being checked can be loaded into a
register once, and then checked against the constants, which can be
immediate data in the opcodes.

One could write a compiler to detect that the bunch of 'if's are all
checking a single value against a series of constants, and maybe some do
that (probably C compilers, if any), and thus get code as good as a
'switch'.

Also, when a 'switch' uses continuous case values (no gaps), you can build
a jump table, which is even better. Lots of C compilers do this.

Lexers typically rely on such switch statement optimizations for speed when
they handle the next character in the input stream, as an example where it
pays off. Of course, the compiler doesn't know you're compiling a lexer, it
just generates better code for switches, either way.

--
harry
Edward Yang
Guest
 
Posts: n/a
#10: Nov 15 '05

re: C# Switch statement


OMG, I thought it is not allowed to do this!

I read MSDN again, and find this:

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

"Stan" <stanly12spamremove@yahoo.com.au> wrote in message
news:eFxvT3RZDHA.652@tk2msftngp13.phx.gbl...[color=blue]
> Here, I did a search and copied one of the many replies to this common
> question.[color=green]
> >[/color]
>
> Yes, like this:
>
> using System;
>
> class Test
> {
>
> public static void Main()
> {
> int x;
> x=Convert.ToInt16(Console.ReadLine());
> switch (x)
> {
> case 1:
> case 2:
> case 3:
> Console.WriteLine("Is 1 2 3");
> break;
> case 4:
> case 5:
> case 6:
> Console.WriteLine("Is 4 5 6");
> break;
> default:
> Console.WriteLine("Is greater than 6");
> break;
> }
> }
> }
>
> However, you can't do greater than/less than (i.e. case 4 to 6) like
> you could do in VB. You'll have to use if/else statements for that.
>
> 'Lib
>
>
>
> "Duncan McNutt [BSDM]" <nutmaster@127.0.0.66> wrote in message
> news:eNPUQtPZDHA.2352@TK2MSFTNGP12.phx.gbl...[color=green]
> > Is it possible to have ranges or patterns in a case ?
> >
> > If not, why wasnt this designed in to make it easier instead of listing
> > every case value needed?
> >
> > --
> >
> > Duncan McNutt
> > Microsoft Product Deactivation Team
> > --
> >
> >
> >
> >[/color]
>
>[/color]


Edward Yang
Guest
 
Posts: n/a
#11: Nov 15 '05

re: C# Switch statement


Sorry, I want to correct a small part of my comment. See Stan's reply in
this thread above this post.

C# does allow the old way of 'stacking' case's.

<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; </msdn>

But do not put any code (comment is OK) after case 0 or case 1, otherwise
the non-fall-through compiler error will get you.

Edward

"Edward Yang" <neo_in_matrix@msn.com> wrote in message
news:%23MRWNcSZDHA.1620@TK2MSFTNGP12.phx.gbl...[color=blue]
> I love C#. But I strongly disagree with M$ C# team on the design of the
> switch-break statement.
>
> C# does not allow automatic fall through for each case statement, yet it
> requires a mandatory and useless break statement. It's completely insane[/color]
to[color=blue]
> have such a design. The break statement is compeletely NOT NECESSARY!
>
> I understand they want to make programmers make LESS errors by breaking
> C/C++ goodness (e.g., range of values). But those errors caused by
> case-break pair never get in my way throughout 8 years of C/C++[/color]
programming[color=blue]
> experience. Actually I've never made a mistake when coding case-break's.
>
> I think they might want to give a compiler warning when there is no break
> statement after a case statement. That's the best way keeping C/C++[/color]
goodness[color=blue]
> yet giving programmers much, much less chance for making errors.
>
> Edward
>
>
> "Duncan McNutt [BSDM]" <nutmaster@127.0.0.66> wrote in message
> news:eNPUQtPZDHA.2352@TK2MSFTNGP12.phx.gbl...[color=green]
> > Is it possible to have ranges or patterns in a case ?
> >
> > If not, why wasnt this designed in to make it easier instead of listing
> > every case value needed?
> >
> > --
> >
> > Duncan McNutt
> > Microsoft Product Deactivation Team
> > --
> >
> >
> >
> >[/color]
>
>[/color]


Michael Culley
Guest
 
Posts: n/a
#12: Nov 15 '05

re: C# Switch statement


> experience. Actually I've never made a mistake when coding case-break's.

Bullshit.

--
Michael Culley


Edward Yang
Guest
 
Posts: n/a
#13: Nov 15 '05

re: C# Switch statement


1..9 or 1 to 9 seems to be 'clean' code.

But, the real truth is that I think the stack of case's is cleaner code.

And, as a C/C++ programmer, we guard cautiously our religion principles :-).
We do not want to borrow something from another religion.

Edward

"Duncan McNutt" <mutmaster@127.0.0.22> wrote in message
news:%238uahxWZDHA.1280@tk2msftngp13.phx.gbl...[color=blue]
> But isnt it more code clean and easier to have
>
> case 1..9:
> or
> case 1 to 9:
>
> instead of
>
> case 1:
> case 2:
> case 3:
> case 4:
> case 5:
> case 6:
> case 7:
> case 8:
> case 9:
> {
> blah();
> break;
> }
>
> get my drift?
>
> I thought C# and .net was about making it more PROBLEM orientated and
> elegant solutions, and not house cleaning of code, well this is one case
> that they have failed in my view.
>
>
>
> --
>
> Duncan McNutt
> Microsoft Product Deactivation Team
> --
>
>
> "Edward Yang" <neo_in_matrix@msn.com> wrote in message
> news:ulyaMoSZDHA.1872@TK2MSFTNGP12.phx.gbl...[color=green]
> > OMG, I thought it is not allowed to do this!
> >
> > I read MSDN again, and find this:
> >
> > Although fall through from one case label to another is not supported,[/color][/color]
it[color=blue]
> is[color=green]
> > allowed to stack case labels, for example:
> > case 0:
> > case 1:
> > // do something;
> > Edward
> >
> > "Stan" <stanly12spamremove@yahoo.com.au> wrote in message
> > news:eFxvT3RZDHA.652@tk2msftngp13.phx.gbl...[color=darkred]
> > > Here, I did a search and copied one of the many replies to this common
> > > question.
> > > >
> > >
> > > Yes, like this:
> > >
> > > using System;
> > >
> > > class Test
> > > {
> > >
> > > public static void Main()
> > > {
> > > int x;
> > > x=Convert.ToInt16(Console.ReadLine());
> > > switch (x)
> > > {
> > > case 1:
> > > case 2:
> > > case 3:
> > > Console.WriteLine("Is 1 2 3");
> > > break;
> > > case 4:
> > > case 5:
> > > case 6:
> > > Console.WriteLine("Is 4 5 6");
> > > break;
> > > default:
> > > Console.WriteLine("Is greater than 6");
> > > break;
> > > }
> > > }
> > > }
> > >
> > > However, you can't do greater than/less than (i.e. case 4 to 6) like
> > > you could do in VB. You'll have to use if/else statements for that.
> > >
> > > 'Lib
> > >
> > >
> > >
> > > "Duncan McNutt [BSDM]" <nutmaster@127.0.0.66> wrote in message
> > > news:eNPUQtPZDHA.2352@TK2MSFTNGP12.phx.gbl...
> > > > Is it possible to have ranges or patterns in a case ?
> > > >
> > > > If not, why wasnt this designed in to make it easier instead of[/color][/color]
> listing[color=green][color=darkred]
> > > > every case value needed?
> > > >
> > > > --
> > > >
> > > > Duncan McNutt
> > > > Microsoft Product Deactivation Team
> > > > --
> > > >
> > > >
> > > >
> > > >
> > >
> > >[/color]
> >
> >[/color]
>
>[/color]


Duncan McNutt
Guest
 
Posts: n/a
#14: Nov 15 '05

re: C# Switch statement


C# isnt C/C++, thats the point MC++ is just a strap on for .NET C# was
designed from the ground up for .NET yet they left things as it was, and now
we're gettin partial types and lambada funtions (anonymous methods) expect
spaghetii code now, generic types is the only real biggie comming in 04 that
I can see, the rest is just gonna cause more problems later on I think.

--

Duncan McNutt
Microsoft Product Deactivation Team
--


"Edward Yang" <neo_in_matrix@msn.com> wrote in message
news:eSg5z#WZDHA.1384@TK2MSFTNGP10.phx.gbl...[color=blue]
> 1..9 or 1 to 9 seems to be 'clean' code.
>
> But, the real truth is that I think the stack of case's is cleaner code.
>
> And, as a C/C++ programmer, we guard cautiously our religion principles[/color]
:-).[color=blue]
> We do not want to borrow something from another religion.
>
> Edward
>
> "Duncan McNutt" <mutmaster@127.0.0.22> wrote in message
> news:%238uahxWZDHA.1280@tk2msftngp13.phx.gbl...[color=green]
> > But isnt it more code clean and easier to have
> >
> > case 1..9:
> > or
> > case 1 to 9:
> >
> > instead of
> >
> > case 1:
> > case 2:
> > case 3:
> > case 4:
> > case 5:
> > case 6:
> > case 7:
> > case 8:
> > case 9:
> > {
> > blah();
> > break;
> > }
> >
> > get my drift?
> >
> > I thought C# and .net was about making it more PROBLEM orientated and
> > elegant solutions, and not house cleaning of code, well this is one case
> > that they have failed in my view.
> >
> >
> >
> > --
> >
> > Duncan McNutt
> > Microsoft Product Deactivation Team
> > --
> >
> >
> > "Edward Yang" <neo_in_matrix@msn.com> wrote in message
> > news:ulyaMoSZDHA.1872@TK2MSFTNGP12.phx.gbl...[color=darkred]
> > > OMG, I thought it is not allowed to do this!
> > >
> > > I read MSDN again, and find this:
> > >
> > > Although fall through from one case label to another is not supported,[/color][/color]
> it[color=green]
> > is[color=darkred]
> > > allowed to stack case labels, for example:
> > > case 0:
> > > case 1:
> > > // do something;
> > > Edward
> > >
> > > "Stan" <stanly12spamremove@yahoo.com.au> wrote in message
> > > news:eFxvT3RZDHA.652@tk2msftngp13.phx.gbl...
> > > > Here, I did a search and copied one of the many replies to this[/color][/color][/color]
common[color=blue][color=green][color=darkred]
> > > > question.
> > > > >
> > > >
> > > > Yes, like this:
> > > >
> > > > using System;
> > > >
> > > > class Test
> > > > {
> > > >
> > > > public static void Main()
> > > > {
> > > > int x;
> > > > x=Convert.ToInt16(Console.ReadLine());
> > > > switch (x)
> > > > {
> > > > case 1:
> > > > case 2:
> > > > case 3:
> > > > Console.WriteLine("Is 1 2 3");
> > > > break;
> > > > case 4:
> > > > case 5:
> > > > case 6:
> > > > Console.WriteLine("Is 4 5 6");
> > > > break;
> > > > default:
> > > > Console.WriteLine("Is greater than 6");
> > > > break;
> > > > }
> > > > }
> > > > }
> > > >
> > > > However, you can't do greater than/less than (i.e. case 4 to 6) like
> > > > you could do in VB. You'll have to use if/else statements for that.
> > > >
> > > > 'Lib
> > > >
> > > >
> > > >
> > > > "Duncan McNutt [BSDM]" <nutmaster@127.0.0.66> wrote in message
> > > > news:eNPUQtPZDHA.2352@TK2MSFTNGP12.phx.gbl...
> > > > > Is it possible to have ranges or patterns in a case ?
> > > > >
> > > > > If not, why wasnt this designed in to make it easier instead of[/color]
> > listing[color=darkred]
> > > > > every case value needed?
> > > > >
> > > > > --
> > > > >
> > > > > Duncan McNutt
> > > > > Microsoft Product Deactivation Team
> > > > > --
> > > > >
> > > > >
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >[/color]
> >
> >[/color]
>
>[/color]


Edward Yang
Guest
 
Posts: n/a
#15: Nov 15 '05

re: C# Switch statement


Yes, there is no absolute EQUALITY in this world. So C# != C/C++. I quite
agree.

But C# borrows or inherits much of C/C++'s language infrastructures. So what
I said in my previous post is applicable to C#.

BTW, what is Microsoft Product Deactivation Team? Is it funded by M$? :-p

Edward

"Duncan McNutt" <mutmaster@127.0.0.22> wrote in message
news:em6YfCXZDHA.1872@TK2MSFTNGP12.phx.gbl...[color=blue]
> C# isnt C/C++, thats the point MC++ is just a strap on for .NET C# was
> designed from the ground up for .NET yet they left things as it was, and[/color]
now[color=blue]
> we're gettin partial types and lambada funtions (anonymous methods) expect
> spaghetii code now, generic types is the only real biggie comming in 04[/color]
that[color=blue]
> I can see, the rest is just gonna cause more problems later on I think.
>
> --
>
> Duncan McNutt
> Microsoft Product Deactivation Team
> --
>
>
> "Edward Yang" <neo_in_matrix@msn.com> wrote in message
> news:eSg5z#WZDHA.1384@TK2MSFTNGP10.phx.gbl...[color=green]
> > 1..9 or 1 to 9 seems to be 'clean' code.
> >
> > But, the real truth is that I think the stack of case's is cleaner code.
> >
> > And, as a C/C++ programmer, we guard cautiously our religion principles[/color]
> :-).[color=green]
> > We do not want to borrow something from another religion.
> >
> > Edward
> >
> > "Duncan McNutt" <mutmaster@127.0.0.22> wrote in message
> > news:%238uahxWZDHA.1280@tk2msftngp13.phx.gbl...[color=darkred]
> > > But isnt it more code clean and easier to have
> > >
> > > case 1..9:
> > > or
> > > case 1 to 9:
> > >
> > > instead of
> > >
> > > case 1:
> > > case 2:
> > > case 3:
> > > case 4:
> > > case 5:
> > > case 6:
> > > case 7:
> > > case 8:
> > > case 9:
> > > {
> > > blah();
> > > break;
> > > }
> > >
> > > get my drift?
> > >
> > > I thought C# and .net was about making it more PROBLEM orientated and
> > > elegant solutions, and not house cleaning of code, well this is one[/color][/color][/color]
case[color=blue][color=green][color=darkred]
> > > that they have failed in my view.
> > >
> > >
> > >
> > > --
> > >
> > > Duncan McNutt
> > > Microsoft Product Deactivation Team
> > > --
> > >
> > >
> > > "Edward Yang" <neo_in_matrix@msn.com> wrote in message
> > > news:ulyaMoSZDHA.1872@TK2MSFTNGP12.phx.gbl...
> > > > OMG, I thought it is not allowed to do this!
> > > >
> > > > I read MSDN again, and find this:
> > > >
> > > > Although fall through from one case label to another is not[/color][/color][/color]
supported,[color=blue][color=green]
> > it[color=darkred]
> > > is
> > > > allowed to stack case labels, for example:
> > > > case 0:
> > > > case 1:
> > > > // do something;
> > > > Edward
> > > >
> > > > "Stan" <stanly12spamremove@yahoo.com.au> wrote in message
> > > > news:eFxvT3RZDHA.652@tk2msftngp13.phx.gbl...
> > > > > Here, I did a search and copied one of the many replies to this[/color][/color]
> common[color=green][color=darkred]
> > > > > question.
> > > > > >
> > > > >
> > > > > Yes, like this:
> > > > >
> > > > > using System;
> > > > >
> > > > > class Test
> > > > > {
> > > > >
> > > > > public static void Main()
> > > > > {
> > > > > int x;
> > > > > x=Convert.ToInt16(Console.ReadLine());
> > > > > switch (x)
> > > > > {
> > > > > case 1:
> > > > > case 2:
> > > > > case 3:
> > > > > Console.WriteLine("Is 1 2 3");
> > > > > break;
> > > > > case 4:
> > > > > case 5:
> > > > > case 6:
> > > > > Console.WriteLine("Is 4 5 6");
> > > > > break;
> > > > > default:
> > > > > Console.WriteLine("Is greater than 6");
> > > > > break;
> > > > > }
> > > > > }
> > > > > }
> > > > >
> > > > > However, you can't do greater than/less than (i.e. case 4 to 6)[/color][/color][/color]
like[color=blue][color=green][color=darkred]
> > > > > you could do in VB. You'll have to use if/else statements for[/color][/color][/color]
that.[color=blue][color=green][color=darkred]
> > > > >
> > > > > 'Lib
> > > > >
> > > > >
> > > > >
> > > > > "Duncan McNutt [BSDM]" <nutmaster@127.0.0.66> wrote in message
> > > > > news:eNPUQtPZDHA.2352@TK2MSFTNGP12.phx.gbl...
> > > > > > Is it possible to have ranges or patterns in a case ?
> > > > > >
> > > > > > If not, why wasnt this designed in to make it easier instead of
> > > listing
> > > > > > every case value needed?
> > > > > >
> > > > > > --
> > > > > >
> > > > > > Duncan McNutt
> > > > > > Microsoft Product Deactivation Team
> > > > > > --
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >[/color]
> >
> >[/color]
>
>[/color]


Duncan McNutt
Guest
 
Posts: n/a
#16: Nov 15 '05

re: C# Switch statement


Absolutely, without MS products our team wouldnt exist :D

--

Duncan McNutt
Microsoft Product Deactivation Team
--


"Edward Yang" <neo_in_matrix@msn.com> wrote in message
news:##hH3RYZDHA.1280@tk2msftngp13.phx.gbl...[color=blue]
> Yes, there is no absolute EQUALITY in this world. So C# != C/C++. I quite
> agree.
>
> But C# borrows or inherits much of C/C++'s language infrastructures. So[/color]
what[color=blue]
> I said in my previous post is applicable to C#.
>
> BTW, what is Microsoft Product Deactivation Team? Is it funded by M$? :-p
>
> Edward
>
> "Duncan McNutt" <mutmaster@127.0.0.22> wrote in message
> news:em6YfCXZDHA.1872@TK2MSFTNGP12.phx.gbl...[color=green]
> > C# isnt C/C++, thats the point MC++ is just a strap on for .NET C# was
> > designed from the ground up for .NET yet they left things as it was, and[/color]
> now[color=green]
> > we're gettin partial types and lambada funtions (anonymous methods)[/color][/color]
expect[color=blue][color=green]
> > spaghetii code now, generic types is the only real biggie comming in 04[/color]
> that[color=green]
> > I can see, the rest is just gonna cause more problems later on I think.
> >
> > --
> >
> > Duncan McNutt
> > Microsoft Product Deactivation Team
> > --
> >
> >
> > "Edward Yang" <neo_in_matrix@msn.com> wrote in message
> > news:eSg5z#WZDHA.1384@TK2MSFTNGP10.phx.gbl...[color=darkred]
> > > 1..9 or 1 to 9 seems to be 'clean' code.
> > >
> > > But, the real truth is that I think the stack of case's is cleaner[/color][/color][/color]
code.[color=blue][color=green][color=darkred]
> > >
> > > And, as a C/C++ programmer, we guard cautiously our religion[/color][/color][/color]
principles[color=blue][color=green]
> > :-).[color=darkred]
> > > We do not want to borrow something from another religion.
> > >
> > > Edward
> > >
> > > "Duncan McNutt" <mutmaster@127.0.0.22> wrote in message
> > > news:%238uahxWZDHA.1280@tk2msftngp13.phx.gbl...
> > > > But isnt it more code clean and easier to have
> > > >
> > > > case 1..9:
> > > > or
> > > > case 1 to 9:
> > > >
> > > > instead of
> > > >
> > > > case 1:
> > > > case 2:
> > > > case 3:
> > > > case 4:
> > > > case 5:
> > > > case 6:
> > > > case 7:
> > > > case 8:
> > > > case 9:
> > > > {
> > > > blah();
> > > > break;
> > > > }
> > > >
> > > > get my drift?
> > > >
> > > > I thought C# and .net was about making it more PROBLEM orientated[/color][/color][/color]
and[color=blue][color=green][color=darkred]
> > > > elegant solutions, and not house cleaning of code, well this is one[/color][/color]
> case[color=green][color=darkred]
> > > > that they have failed in my view.
> > > >
> > > >
> > > >
> > > > --
> > > >
> > > > Duncan McNutt
> > > > Microsoft Product Deactivation Team
> > > > --
> > > >
> > > >
> > > > "Edward Yang" <neo_in_matrix@msn.com> wrote in message
> > > > news:ulyaMoSZDHA.1872@TK2MSFTNGP12.phx.gbl...
> > > > > OMG, I thought it is not allowed to do this!
> > > > >
> > > > > I read MSDN again, and find this:
> > > > >
> > > > > Although fall through from one case label to another is not[/color][/color]
> supported,[color=green][color=darkred]
> > > it
> > > > is
> > > > > allowed to stack case labels, for example:
> > > > > case 0:
> > > > > case 1:
> > > > > // do something;
> > > > > Edward
> > > > >
> > > > > "Stan" <stanly12spamremove@yahoo.com.au> wrote in message
> > > > > news:eFxvT3RZDHA.652@tk2msftngp13.phx.gbl...
> > > > > > Here, I did a search and copied one of the many replies to this[/color]
> > common[color=darkred]
> > > > > > question.
> > > > > > >
> > > > > >
> > > > > > Yes, like this:
> > > > > >
> > > > > > using System;
> > > > > >
> > > > > > class Test
> > > > > > {
> > > > > >
> > > > > > public static void Main()
> > > > > > {
> > > > > > int x;
> > > > > > x=Convert.ToInt16(Console.ReadLine());
> > > > > > switch (x)
> > > > > > {
> > > > > > case 1:
> > > > > > case 2:
> > > > > > case 3:
> > > > > > Console.WriteLine("Is 1 2 3");
> > > > > > break;
> > > > > > case 4:
> > > > > > case 5:
> > > > > > case 6:
> > > > > > Console.WriteLine("Is 4 5 6");
> > > > > > break;
> > > > > > default:
> > > > > > Console.WriteLine("Is greater than 6");
> > > > > > break;
> > > > > > }
> > > > > > }
> > > > > > }
> > > > > >
> > > > > > However, you can't do greater than/less than (i.e. case 4 to 6)[/color][/color]
> like[color=green][color=darkred]
> > > > > > you could do in VB. You'll have to use if/else statements for[/color][/color]
> that.[color=green][color=darkred]
> > > > > >
> > > > > > 'Lib
> > > > > >
> > > > > >
> > > > > >
> > > > > > "Duncan McNutt [BSDM]" <nutmaster@127.0.0.66> wrote in message
> > > > > > news:eNPUQtPZDHA.2352@TK2MSFTNGP12.phx.gbl...
> > > > > > > Is it possible to have ranges or patterns in a case ?
> > > > > > >
> > > > > > > If not, why wasnt this designed in to make it easier instead[/color][/color][/color]
of[color=blue][color=green][color=darkred]
> > > > listing
> > > > > > > every case value needed?
> > > > > > >
> > > > > > > --
> > > > > > >
> > > > > > > Duncan McNutt
> > > > > > > Microsoft Product Deactivation Team
> > > > > > > --
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >[/color]
> >
> >[/color]
>
>[/color]


Peter Vidler
Guest
 
Posts: n/a
#17: Nov 15 '05

re: C# Switch statement


Hi,
[color=blue]
> but I do NOT remember I ever made a mistake with case-break's.[/color]

Maybe YOU don't (doubtful), but many people do. Hence the design decision.

You almost never want a case statement to fall through if there is code in
it.. so enforcing an explicit break or goto makes perfect sense. Isn't it
this same case that was the reason goto was kept in c# (just to move between
cases in switch statements)?

Pete


Frank Eller [MVP]
Guest
 
Posts: n/a
#18: Nov 15 '05

re: C# Switch statement


Hi Edward,

"Edward Yang" <neo_in_matrix@msn.com> schrieb im Newsbeitrag
news:OIE6umSZDHA.2284@TK2MSFTNGP10.phx.gbl...[color=blue]
>
> "Frank Eller [MVP]" <webmaster@frankeller.de> wrote in message
> news:%23G0$M7PZDHA.1872@TK2MSFTNGP12.phx.gbl...[color=green]
> > Hi Duncan,
> >[color=darkred]
> > > Is it possible to have ranges or patterns in a case ?[/color]
> >
> > No.
> >[/color]
>
> It is a half yes. See Stan's reply in this thread.
>[/color]

Well, I agree that it's possible to execute a piece of code for more than
one value, but that's not exactly what he meant ... because you have to
write down the "case"-part, which you would not have to do if you could use
a range like in VB.NET. But ok, let's call it a "half yes ..." :-)).

REgards,

--
Frank Eller [.NET MVP]
www.frankeller.de
..NET Developers Group Munich- www.munichdot.net


Rob Tillie
Guest
 
Posts: n/a
#19: Nov 15 '05

re: C# Switch statement


Deactivate Windows xp's? Deactivate Microsoft? :|
You have certainly no affiliation with Microsoft, just remove it so nobody
gets confused...

GReetz,
-- Rob.

Edward Yang wrote:[color=blue]
> So~~~ what do your team do?
>
> Edward[/color]


Duncan .McNutt
Guest
 
Posts: n/a
#20: Nov 15 '05

re: C# Switch statement


No :> I can put what i fluckin want. You dont have to read it.

--

Duncan McNutt
Microsoft Product Deactivation Team
--


"Rob Tillie" <Rob.Tillie@student.tul.edu> wrote in message
news:ebq77FcZDHA.2256@TK2MSFTNGP10.phx.gbl...[color=blue]
> Deactivate Windows xp's? Deactivate Microsoft? :|
> You have certainly no affiliation with Microsoft, just remove it so nobody
> gets confused...
>
> GReetz,
> -- Rob.
>
> Edward Yang wrote:[color=green]
> > So~~~ what do your team do?
> >
> > Edward[/color]
>
>[/color]


Duncan .McNutt
Guest
 
Posts: n/a
#21: Nov 15 '05

re: C# Switch statement


You have no idea what I have affiliations with so bite me little man

--

Duncan McNutt
Microsoft Product Deactivation Team
--


"Duncan .McNutt" <futmaster@127.0.0.99> wrote in message
news:uqjvfIcZDHA.4028@tk2msftngp13.phx.gbl...[color=blue]
> No :> I can put what i fluckin want. You dont have to read it.
>
> --
>
> Duncan McNutt
> Microsoft Product Deactivation Team
> --
>
>
> "Rob Tillie" <Rob.Tillie@student.tul.edu> wrote in message
> news:ebq77FcZDHA.2256@TK2MSFTNGP10.phx.gbl...[color=green]
> > Deactivate Windows xp's? Deactivate Microsoft? :|
> > You have certainly no affiliation with Microsoft, just remove it so[/color][/color]
nobody[color=blue][color=green]
> > gets confused...
> >
> > GReetz,
> > -- Rob.
> >
> > Edward Yang wrote:[color=darkred]
> > > So~~~ what do your team do?
> > >
> > > Edward[/color]
> >
> >[/color]
>
>[/color]


Eric Gunnerson [MS]
Guest
 
Posts: n/a
#22: Nov 15 '05

re: C# Switch statement


It's a feature vs. complexity thing.. While we agree that there are cases
where case ranges are useful, we don't think that their usefullness above
what you get with a simple series of if statements outweighs the increase in
complexity.

--
Eric Gunnerson

Visit the C# product team at http://www.csharp.net
Eric's blog is at http://blogs.gotdotnet.com/ericgu/

This posting is provided "AS IS" with no warranties, and confers no rights.
"Duncan McNutt [BSDM]" <nutmaster@127.0.0.66> wrote in message
news:eNPUQtPZDHA.2352@TK2MSFTNGP12.phx.gbl...[color=blue]
> Is it possible to have ranges or patterns in a case ?
>
> If not, why wasnt this designed in to make it easier instead of listing
> every case value needed?
>
> --
>
> Duncan McNutt
> Microsoft Product Deactivation Team
> --
>
>
>
>[/color]


Duncan .McNutt
Guest
 
Posts: n/a
#23: Nov 15 '05

re: C# Switch statement


Complexity for whom?

--

Duncan McNutt
Microsoft Product Deactivation Team
--


"Eric Gunnerson [MS]" <ericgu@online.microsoft.com> wrote in message
news:ePk$macZDHA.2336@TK2MSFTNGP09.phx.gbl...[color=blue]
> It's a feature vs. complexity thing.. While we agree that there are cases
> where case ranges are useful, we don't think that their usefullness above
> what you get with a simple series of if statements outweighs the increase[/color]
in[color=blue]
> complexity.
>
> --
> Eric Gunnerson
>
> Visit the C# product team at http://www.csharp.net
> Eric's blog is at http://blogs.gotdotnet.com/ericgu/
>
> This posting is provided "AS IS" with no warranties, and confers no[/color]
rights.[color=blue]
> "Duncan McNutt [BSDM]" <nutmaster@127.0.0.66> wrote in message
> news:eNPUQtPZDHA.2352@TK2MSFTNGP12.phx.gbl...[color=green]
> > Is it possible to have ranges or patterns in a case ?
> >
> > If not, why wasnt this designed in to make it easier instead of listing
> > every case value needed?
> >
> > --
> >
> > Duncan McNutt
> > Microsoft Product Deactivation Team
> > --
> >
> >
> >
> >[/color]
>
>[/color]


Duncan McNutt [FTSE].
Guest
 
Posts: n/a
#24: Nov 15 '05

re: C# Switch statement


So a little thing like that that may aid code readability is not good but
adding crap like Lambada functions (anonymous methods) and partial types (
to aid splitting source files) that is good?

You have the BCLs make an entire pigs mess of VSplits and HSplits and you
say thats good?

Yet adding a simple thing like ranges into a case in the switch construct is
bad because you cant be assed to handle the complexity?

Pass the bong.


--

Duncan McNutt
Microsoft Product Deactivation Team
--


"Eric Gunnerson [MS]" <ericgu@online.microsoft.com> wrote in message
news:ePk$macZDHA.2336@TK2MSFTNGP09.phx.gbl...[color=blue]
> It's a feature vs. complexity thing.. While we agree that there are cases
> where case ranges are useful, we don't think that their usefullness above
> what you get with a simple series of if statements outweighs the increase[/color]
in[color=blue]
> complexity.
>
> --
> Eric Gunnerson
>
> Visit the C# product team at http://www.csharp.net
> Eric's blog is at http://blogs.gotdotnet.com/ericgu/
>
> This posting is provided "AS IS" with no warranties, and confers no[/color]
rights.[color=blue]
> "Duncan McNutt [BSDM]" <nutmaster@127.0.0.66> wrote in message
> news:eNPUQtPZDHA.2352@TK2MSFTNGP12.phx.gbl...[color=green]
> > Is it possible to have ranges or patterns in a case ?
> >
> > If not, why wasnt this designed in to make it easier instead of listing
> > every case value needed?
> >
> > --
> >
> > Duncan McNutt
> > Microsoft Product Deactivation Team
> > --
> >
> >
> >
> >[/color]
>
>[/color]


Duncan McNutt [ FTSE ]
Guest
 
Posts: n/a
#25: Nov 15 '05

re: C# Switch statement


Sign of a good person is admiting they made mistakes and learnt from them.

Hiding them is just weak.

--

Duncan McNutt
Microsoft Product Deactivation Team
--


"Michael Culley" <mculley@NOSPAMoptushome.com.au> wrote in message
news:OIMkFDdZDHA.2344@TK2MSFTNGP09.phx.gbl...[color=blue][color=green]
> > What I said is nothing but TRUTH! I admit that I often make mistakes[/color][/color]
with[color=blue][color=green]
> > such code like
> >
> > <code>
> > if(var = 1)
> > </code>
> >
> > but I do NOT remember I ever made a mistake with case-break's.[/color]
>
> If you've been coding in C for 8 years you have made this mistake, even if[/color]
you don't remember or are too macho to admit it.[color=blue]
>[color=green]
> > Keep on pratising with C/C++, Michael![/color]
>
> Keep on pratising your spelling, Edward!
>
> --
> Michael Culley
>
>[/color]


Edward Yang
Guest
 
Posts: n/a
#26: Nov 15 '05

re: C# Switch statement



"Michael Culley" <mculley@NOSPAMoptushome.com.au> wrote in message
news:OIMkFDdZDHA.2344@TK2MSFTNGP09.phx.gbl...[color=blue][color=green]
> > What I said is nothing but TRUTH! I admit that I often make mistakes[/color][/color]
with[color=blue][color=green]
> > such code like
> >
> > <code>
> > if(var = 1)
> > </code>
> >
> > but I do NOT remember I ever made a mistake with case-break's.[/color]
>
> If you've been coding in C for 8 years you have made this mistake, even if[/color]
you don't remember or are too macho to admit it.

No, I never made such a mistake as far as I can remember.
[color=blue]
>[color=green]
> > Keep on pratising with C/C++, Michael![/color]
>
> Keep on pratising your spelling, Edward![/color]

Thanks for you encourage!
[color=blue]
>
> --
> Michael Culley
>
>[/color]


Edward Yang
Guest
 
Posts: n/a
#27: Nov 15 '05

re: C# Switch statement



"Peter Vidler" <pvidler@gawab.com> wrote in message
news:fF40b.625$tS2.104034@newsfep2-win.server.ntli.net...[color=blue]
> Hi,
>[color=green]
> > but I do NOT remember I ever made a mistake with case-break's.[/color]
>
> Maybe YOU don't (doubtful), but many people do. Hence the design decision.[/color]

Pete, note that many != all!
[color=blue]
>
> You almost never want a case statement to fall through if there is code in
> it.. so enforcing an explicit break or goto makes perfect sense. Isn't it
> this same case that was the reason goto was kept in c# (just to move[/color]
between[color=blue]
> cases in switch statements)?
>
> Pete
>
>[/color]


Austin Ehlers
Guest
 
Posts: n/a
#28: Nov 15 '05

re: C# Switch statement


On Mon, 18 Aug 2003 13:23:33 -0700, "Eric Gunnerson [MS]"
<ericgu@online.microsoft.com> wrote:
[color=blue]
>It's a feature vs. complexity thing.. While we agree that there are cases
>where case ranges are useful, we don't think that their usefullness above
>what you get with a simple series of if statements outweighs the increase in
>complexity.[/color]

I agree. However, what about adding syntax like this:

switch (num)
{
case 1 to 5:
//code
break;
}

and translate it to the appropriate IL as if it were written like:

switch (num)
{
case 1:
case 2:
case 3:
case 4:
case 5:
//code
break;
}

As this allows increased readability and is easily maintainable?

Thanks,
Austin Ehlers
Duncan McNutt [FTSE]_
Guest
 
Posts: n/a
#29: Nov 15 '05

re: C# Switch statement


That is complex??


But theyre adding Lambada funtions (anonymous methods) and Partial types!!!

Thats even MORE complex and POINTLESS !!!

--

Duncan McNutt
Microsoft Product Deactivation Team
--


"Austin Ehlers" <the*remove*bored*me*guy16@hotmail.com> wrote in message
news:h043kv4cei6lnn03r7lrdd71kfl9r7d83n@4ax.com...[color=blue]
> On Mon, 18 Aug 2003 13:23:33 -0700, "Eric Gunnerson [MS]"
> <ericgu@online.microsoft.com> wrote:
>[color=green]
> >It's a feature vs. complexity thing.. While we agree that there are cases
> >where case ranges are useful, we don't think that their usefullness above
> >what you get with a simple series of if statements outweighs the increase[/color][/color]
in[color=blue][color=green]
> >complexity.[/color]
>
> I agree. However, what about adding syntax like this:
>
> switch (num)
> {
> case 1 to 5:
> //code
> break;
> }
>
> and translate it to the appropriate IL as if it were written like:
>
> switch (num)
> {
> case 1:
> case 2:
> case 3:
> case 4:
> case 5:
> //code
> break;
> }
>
> As this allows increased readability and is easily maintainable?
>
> Thanks,
> Austin Ehlers[/color]


Peter Vidler
Guest
 
Posts: n/a
#30: Nov 15 '05

re: C# Switch statement


>>> but I do NOT remember I ever made a mistake with case-break's.[color=blue][color=green]
>>
>> Maybe YOU don't (doubtful), but many people do. Hence the design
>> decision.[/color]
>
> Pete, note that many != all![/color]

True, but language features should be designed around what many people will
find useful. Requiring a break or goto statement means you will get a
compile time error.. the alternative is an annoying-to-debug runtime
error -- which would you prefer? I would rather not debug a runtime error
just so the fraction of programmers who never make these mistakes will not
be so irritated with the switch statement (they can just use if-else if they
don't like it).

It should be noted that this is generation of a compile time error is
reminiscent of C++ (where strong typing generated compile time errors, and C
would only produce runtime errors). It's just taken one step further.

Pete


Duncan McNutt .[FTSE]
Guest
 
Posts: n/a
#31: Nov 15 '05

re: C# Switch statement


yeah i know its a joke duh


Lambda functions will lead to spagheti code, look at the use of them today
in other languages... Dont be so nieve that it wont be.

yes there are places when they may help but I really am worried about the
misuse of them.

Seems to be in the next release they will be added.

Same for partial types, if you need those, think about the design.

Generic types however are long overdue.


--

Duncan McNutt
Microsoft Product Deactivation Team
--


"Peter Vidler" <pvidler@gawab.com> wrote in message
news:Fbp0b.23$gc6.30932@newsfep1-win.server.ntli.net...[color=blue][color=green]
> > But theyre adding Lambada funtions (anonymous methods) and Partial
> > types!!![/color]
>
> I thought Lambada was a style of dancing? I might be wrong, but I thought
> anonymous functions were Lambda functions.
>
> The extra complexity of Lambda functions is useful.. ranges in switch
> statements are not. Just use if-else, it's usually more readable for
> situations where ranges are required anyway.
>
> Also, is it definite that Lambda functions are being added? I thought new
> features for C# had to go through a standardisation process before[/color]
becoming[color=blue]
> part of the language?
>
> Pete
>
>[/color]


craig
Guest
 
Posts: n/a
#32: Nov 15 '05

re: C# Switch statement


Amen.

"Austin Ehlers" <the*remove*bored*me*guy16@hotmail.com> wrote in message
news:h043kv4cei6lnn03r7lrdd71kfl9r7d83n@4ax.com...[color=blue]
> On Mon, 18 Aug 2003 13:23:33 -0700, "Eric Gunnerson [MS]"
> <ericgu@online.microsoft.com> wrote:
>[color=green]
> >It's a feature vs. complexity thing.. While we agree that there are cases
> >where case ranges are useful, we don't think that their usefullness above
> >what you get with a simple series of if statements outweighs the increase[/color][/color]
in[color=blue][color=green]
> >complexity.[/color]
>
> I agree. However, what about adding syntax like this:
>
> switch (num)
> {
> case 1 to 5:
> //code
> break;
> }
>
> and translate it to the appropriate IL as if it were written like:
>
> switch (num)
> {
> case 1:
> case 2:
> case 3:
> case 4:
> case 5:
> //code
> break;
> }
>
> As this allows increased readability and is easily maintainable?
>
> Thanks,
> Austin Ehlers[/color]


Eric Gunnerson [MS]
Guest
 
Posts: n/a
#33: Nov 15 '05

re: C# Switch statement


Both partial types and anonymous methods allow us to deal with situations
where C# does not work very well, and therefore the benefit that they bring
is higher than the benefit that case ranges would bring.

Partial types will let us segregate Windows Forms code into
designer-generated code and user code. That will make the model much easier.
There are other scenarios, but that's the primary one.

Anonymous methods are very useful in a case where you need a small bit of
code to pass as a delegate. If you put it in a separate method, you end up
with a disconnect between the small bit of code and where it's actually
used, which makes it harder to understand what's going on. If used for
scenarios such as this, anonymous methods will make your code more readable.

There is the chance for abuse with both features.

--
Eric Gunnerson

Visit the C# product team at http://www.csharp.net
Eric's blog is at http://blogs.gotdotnet.com/ericgu/

This posting is provided "AS IS" with no warranties, and confers no rights.
"Duncan McNutt [FTSE]." <futmaster@127.0.0.707> wrote in message
news:OdbkV5cZDHA.1740@TK2MSFTNGP10.phx.gbl...[color=blue]
> So a little thing like that that may aid code readability is not good but
> adding crap like Lambada functions (anonymous methods) and partial types (
> to aid splitting source files) that is good?
>
> You have the BCLs make an entire pigs mess of VSplits and HSplits and you
> say thats good?
>
> Yet adding a simple thing like ranges into a case in the switch construct[/color]
is[color=blue]
> bad because you cant be assed to handle the complexity?
>
> Pass the bong.
>
>
> --
>
> Duncan McNutt
> Microsoft Product Deactivation Team
> --
>
>
> "Eric Gunnerson [MS]" <ericgu@online.microsoft.com> wrote in message
> news:ePk$macZDHA.2336@TK2MSFTNGP09.phx.gbl...[color=green]
> > It's a feature vs. complexity thing.. While we agree that there are[/color][/color]
cases[color=blue][color=green]
> > where case ranges are useful, we don't think that their usefullness[/color][/color]
above[color=blue][color=green]
> > what you get with a simple series of if statements outweighs the[/color][/color]
increase[color=blue]
> in[color=green]
> > complexity.
> >
> > --
> > Eric Gunnerson
> >
> > Visit the C# product team at http://www.csharp.net
> > Eric's blog is at http://blogs.gotdotnet.com/ericgu/
> >
> > This posting is provided "AS IS" with no warranties, and confers no[/color]
> rights.[color=green]
> > "Duncan McNutt [BSDM]" <nutmaster@127.0.0.66> wrote in message
> > news:eNPUQtPZDHA.2352@TK2MSFTNGP12.phx.gbl...[color=darkred]
> > > Is it possible to have ranges or patterns in a case ?
> > >
> > > If not, why wasnt this designed in to make it easier instead of[/color][/color][/color]
listing[color=blue][color=green][color=darkred]
> > > every case value needed?
> > >
> > > --
> > >
> > > Duncan McNutt
> > > Microsoft Product Deactivation Team
> > > --
> > >
> > >
> > >
> > >[/color]
> >
> >[/color]
>
>[/color]


Eric Gunnerson [MS]
Guest
 
Posts: n/a
#34: Nov 15 '05

re: C# Switch statement


I'd have to see some actual code to understand how common this was and
whether it made sense to have a syntax for it. If it were only cases 1 - 5,
you'd obviously write it with a single-clause if. If there are a lot more
cases, I might be persuaded that it would be clearer to have a range. It
would take a fair bit of data to understand what people were really doing
and what the result of a new feature would be.

My experience is that switch statements are fairly rare in OO code.

--
Eric Gunnerson

Visit the C# product team at http://www.csharp.net
Eric's blog is at http://blogs.gotdotnet.com/ericgu/

This posting is provided "AS IS" with no warranties, and confers no rights.
"Austin Ehlers" <the*remove*bored*me*guy16@hotmail.com> wrote in message
news:h043kv4cei6lnn03r7lrdd71kfl9r7d83n@4ax.com...[color=blue]
> On Mon, 18 Aug 2003 13:23:33 -0700, "Eric Gunnerson [MS]"
> <ericgu@online.microsoft.com> wrote:
>[color=green]
> >It's a feature vs. complexity thing.. While we agree that there are cases
> >where case ranges are useful, we don't think that their usefullness above
> >what you get with a simple series of if statements outweighs the increase[/color][/color]
in[color=blue][color=green]
> >complexity.[/color]
>
> I agree. However, what about adding syntax like this:
>
> switch (num)
> {
> case 1 to 5:
> //code
> break;
> }
>
> and translate it to the appropriate IL as if it were written like:
>
> switch (num)
> {
> case 1:
> case 2:
> case 3:
> case 4:
> case 5:
> //code
> break;
> }
>
> As this allows increased readability and is easily maintainable?
>
> Thanks,
> Austin Ehlers[/color]


Rob Tillie
Guest
 
Posts: n/a
#35: Nov 15 '05

re: C# Switch statement


Nope and you don't seem to want to tell us.
However, I saw you recommend somewhere to someone who lost his XP serial to
"get a key generator."
I cannot imagine someone from MS telling that.

Greetz,
-- Rob.


Duncan .McNutt wrote:[color=blue]
> You have no idea what I have affiliations with so bite me little man
>
> --
>
> Duncan McNutt
> Microsoft Product Deactivation Team
>
> "Duncan .McNutt" <futmaster@127.0.0.99> wrote in message
> news:uqjvfIcZDHA.4028@tk2msftngp13.phx.gbl...[color=green]
>> No :> I can put what i fluckin want. You dont have to read it.
>>
>> --
>>
>> Duncan McNutt
>> Microsoft Product Deactivation Team
>> --
>>
>>
>> "Rob Tillie" <Rob.Tillie@student.tul.edu> wrote in message
>> news:ebq77FcZDHA.2256@TK2MSFTNGP10.phx.gbl...[color=darkred]
>>> Deactivate Windows xp's? Deactivate Microsoft? :|
>>> You have certainly no affiliation with Microsoft, just remove it so
>>> nobody gets confused...
>>>
>>> GReetz,
>>> -- Rob.
>>>
>>> Edward Yang wrote:
>>>> So~~~ what do your team do?
>>>>
>>>> Edward[/color][/color][/color]


Closed Thread