Re: switch
- From: "Daniel O'Connell [C# MVP]" <onyxkirx@xxxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 3 Feb 2006 15:52:42 -0600
"James Curran" <jamescurran@xxxxxxxx> wrote in message
news:exKlDDQKGHA.1192@xxxxxxxxxxxxxxxxxxxxxxx
"Michael S" <no@xxxxxxxx> wrote in message
news:OdmcFt2JGHA.2248@xxxxxxxxxxxxxxxxxxxxxxx
I hate when VB does stuff better than C#. I wonder why switch is solimited
in C#, anyone knows why?
You're looking at it from the wrong point of view. When C was being
designed (in the 1970's), they added if() to the language, but they wanted
a
way to do something which could not be easily done with nested if()s,
specifically, a jump table (and other optimizations). So, they created
the
switch statement. When C begat C++ and when C++ begat C#, the syntax was
carried forward, but more importantly, the functionality was also carried
forward.
Years later, the VB designers though C's switch statement looked cool,
and decided to add it to VB (renaming it Select) (actually I think it
entered the language in the MSDOS/QuickBasic era). However, it is purely
cosmetic --- VB's Select does *nothing* that nested IFs don't do -- It
probably even compiles to identical code.
One would think that a clever compiler designer would be able to dream up a
switch that can do either, they've already added string support to the C#
version which isn't quite a jump table(it does use a hashtable at some point
I think) and multiple labels. Allowing range shortcuts, if not whole
expressions, at some acceptable level of performance shouldn't be impossible
in the modern day.
.
- References:
- switch
- From: Evan Camilleri
- Re: switch
- From: Michael S
- Re: switch
- From: James Curran
- switch
- Prev by Date: Converting 1.0 form to 2.0?
- Next by Date: RichTextBox bug?
- Previous by thread: Re: switch
- Next by thread: MailFormat - sending email messages with carriage return
- Index(es):
Relevant Pages
|