473,666 Members | 2,382 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

switch statement

I know you can stack case(s)

case 1:
case 2:
but can you have ranges as in vb.net does like ( 1 to 6 ) type of thing, or
<n or n etc.


Jan 26 '08 #1
10 2074
Just Me wrote:
I know you can stack case(s)

case 1:
case 2:
but can you have ranges as in vb.net does like ( 1 to 6 ) type of
thing, or <n or n etc.
No, you can't. So in those situations, you either have to stack cases
on top of eachother or use a christmastree of if/else statements :)

FB

--
------------------------------------------------------------------------
Lead developer of LLBLGen Pro, the productive O/R mapper for .NET
LLBLGen Pro website: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------
Jan 26 '08 #2
"Just Me" <news.microsoft .comwrote in message
news:ug******** ******@TK2MSFTN GP06.phx.gbl...
>I know you can stack case(s)

case 1:
case 2:
but can you have ranges as in vb.net does like ( 1 to 6 ) type of thing,
or <n or n etc.
No, not in C#. You will have to stack some "if... else if..." blocks to
do that.
Jan 26 '08 #3
Just Me wrote:
Maybe its just me, but this seems a bit limiting really. vb.net select/case
case(s) are more flexible than c# in this particular case ( no pun
intended ).
In general it is not good for a language to get all possible
features (PL/I, Ada etc. show how that goes).

So features are prioritized. And this one ended up below the
line for C#.

I don't have a problem with that. I think it is relative rare
to want to do that *and* the code are in need not for some cleanup.

Arne
Jan 26 '08 #4
Jon Skeet [C# MVP] wrote:
<"Just Me" <news.microsoft .com>wrote:
>Maybe its just me, but this seems a bit limiting really. vb.net select/case
case(s) are more flexible than c# in this particular case ( no pun
intended ).

They're just different ways of expressing the same thing. Depending on
the ranges involved, the VB compiler may choose to compile it as an
if/else anyway.
Wouldn't it always ?

Or does x86 instruction set have a CASE instruction ?

Arne
Jan 26 '08 #5
Just Me,

This is a dead horse, even Jon Skeet writes on his pages that the Select
case from VB for Net is better than the C# switch.

Cor

Jan 28 '08 #6
Jon,
>I'm talking about VB9 etc - VB.NET, effectively.
VB 2002 - VB 2008, VB7 to VB9 are inhouse development codes like Orca and
things like that.

Cor

Jan 28 '08 #7
On Jan 28, 4:55 am, "Cor Ligthert[MVP]" <notmyfirstn... @planet.nl>
wrote:
This is a dead horse, even Jon Skeet writes on his pages that the Select
case from VB for Net is better than the C# switch.
Where exactly do I do that? I can't remember doing so, nor can I find
it on my FAQ page, which is the only page I can remember comparing VB
and C#.

There are certainly issues with C#'s switch statement, but if we were
to allow ranges I'd want a lot more than that at the same time.

Jon
Jan 28 '08 #8
Jon,

Sorry I thought it was on your pages, probably you have only written this
sometimes.
(And from that I am sure, I don't remember if it was in which newsgroup
anymore).
Cor

Jan 28 '08 #9
Cor Ligthert[MVP] wrote:
VB 2002 - VB 2008, VB7 to VB9 are inhouse development codes like Orca
and things like that.
Versions numbers has become a mess.

VS 2008 - C# compiler 3.5 - C# language 3.0
VS 2008 - MS VC++ 9.0 - MS C++ 15.0

Of course VB is messed up.

(and not that Java is better, Java 2 SE 1.4 -Java 2 SE 5 ->
Java SE 6 is the same mess)

It should be forbidden by law to change names and version numbering
schemes for software.

Arne
Jan 29 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
10904
by: Myster Ious | last post by:
Polymorphism replaces switch statements, making the code more compact/readable/maintainable/OO whatever, fine! What I understand, that needs to be done at the programming level, is this: a switch-case has a variable (most probably an enumeration) & associated symbols or integral value. Selection is made, base on what symbol/value the variable holds. So
35
8331
by: Thomas Matthews | last post by:
Hi, My son is writing a program to move a character. He is using the numbers on the keypad to indicate the direction of movement: 7 8 9 4 5 6 1 2 3 Each number has a direction except for '5'. So in his switch statement, he omits a case for '5':
17
2811
by: prafulla | last post by:
Hi all, I don't have a copy of C standard at hand and so anyone of you can help me. I have always wondered how switch statements are so efficient in jumping to the right case (if any)? Can anybody point me to the innards of it please? Sorry if this is OT on clc and more relevant to comp.compilers. I am confused here too.
5
6101
by: Alvin Bruney | last post by:
Is a switch more efficient than an if statement? I observe thru the debugger that a switch statement jumps directly to its case handler where as an if statement examines all conditions sequentially. Is that a trick of the debugger or is a switch quicker by O(n).
3
19735
by: pgraeve | last post by:
I am a convert from VB to C# so bear with me on this "conversion" question C# switch statement seems to be the closest relative to VB's Select Case. I used VB's Select Case statement liberally. Now I find myself wanting to use "Select Case" i.e., "switch" in C# regularly, but I always have to find another way b/c C#'s switch statement only allows static or integral variables. For example, I often want to use a switch statement based on the...
27
5631
by: Yuriy Solodkyy | last post by:
Hi VS 2005 beta 2 successfully compiles the following: using System; using System.Collections.Generic; using System.Text; namespace ConsoleApplication1 { class Program {
25
18376
by: v4vijayakumar | last post by:
'continue' within switch actually associated with the outer 'while' loop. Is this behavior protable? int ch = '\n'; while (true) { switch(ch) { case '\n': cout << "test"; continue; } }
12
12317
by: | last post by:
Is it fine to call another method from Switch? Eg. Switch (stringVar) { case ("a"): somVar = "whatever"; Another_Method(); //call another method return;
2
1450
by: Phillip B Oldham | last post by:
What would be the optimal/pythonic way to subject an object to a number of tests (based on the object's attributes) and redirect program flow? Say I had the following: pets = {'name': 'fluffy', 'species': 'cat', 'size': 'small'} pets = {'name': 'bruno', 'species': 'snake', 'size': 'small'} pets = {'name': 'rex', 'species': 'dog', 'size': 'large'}
13
11808
by: Satya | last post by:
Hi everyone, This is the first time iam posting excuse me if iam making any mistake. My question is iam using a switch case statement in which i have around 100 case statements to compare. so just curious to find out is it effective to use this method?? or is there is any other alternative method present so that execution time and code size can be reduced?? Thanks in advance.
0
8440
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8352
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8863
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8780
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7378
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4192
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4358
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2765
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2005
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.