The annoying thing about C#.....  | |
October 1st, 2002, 03:39 AM
|
#1 (permalink)
| | Member
Join Date: Sep 2002
Posts: 364
| The annoying thing about C#.....
Is I don't think there is a way to use a switch statement with a non explicit value. Meaning you can't have a case < 10. Has to be 10, or 20, or a string, or char or whatever.
If there is a way I can't find it anywhere. Can you still use case < 10 in VB.Net? |
| |
October 1st, 2002, 03:47 AM
|
#2 (permalink)
| | Not Really a Member
Join Date: Oct 2001
Posts: 25,395
|
errmm... why can't you 
that's just retarded
guess you could put...
case 1
case 2
case 3
case 4
....
case 10
do something  lol
if you try it, it fails on compile?!?!
__________________
Helicopters don't fly; they vibrate so much and make so much noise that the earth rejects them.
|
| |
October 1st, 2002, 03:57 AM
|
#3 (permalink)
| | Member
Join Date: Sep 2002
Posts: 364
|
Yeah but even case 1, case 2, would be longer than nested if's because I go up to 85.
Underlines it in red as soon as I go "case < 10". |
| |
October 1st, 2002, 04:10 AM
|
#4 (permalink)
| | Not Really a Member
Join Date: Oct 2001
Posts: 25,395
|
yeah I tried it over here too
*mental note, C# sucks*  lol
yeah I did some poking around, a lot of people seem to be bashing the INeffectiveness of C#'s switch statement...
looks like some nasty long elseif statements 
Also saw you HAVE to put in break statements or GOTO (LOL) statements after every case ... ptttht
I'm gonna start learning C++ again.. staying away from C#  |
| |
October 1st, 2002, 04:15 AM
|
#5 (permalink)
| | Member
Join Date: Sep 2002
Posts: 364
|
Yeah, it took me a while to figure out about the breaks needing to be put in there. Overall, C# seems a lot easier than C++, at least for RAD. But I've had very minor C++ exposure. |
| |
October 1st, 2002, 01:19 PM
|
#6 (permalink)
| | Member
Join Date: Feb 2002
Posts: 161
| Re: The annoying thing about C#.....
The same restrictions apply to switch statements in C, C++, and Java (and probably a few other languages). I imagine that it would be more difficult for the compiler to optimize ranged value comparisons, while a series of literal value comparisons can be compiled directly to a jump table. |
| |
October 1st, 2002, 09:30 PM
|
#7 (permalink)
| | Member
Join Date: Sep 2002
Posts: 364
|
You don't have to break after every case in Java. Although you should anyways, but sometimes I'm lazy
You might think that this would be a feature MS would have implemented, however, since VB had it, and C# was made to be more RADish than C++. |
| | | Thread Tools | Search this Thread | | | | |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | | | | Most Active Discussions | | | | | Recent Discussions  | | | | | |