4Learning
asked on
negative values in case statements
Hello experts
Can a negative value be passed to a switch/case statement in C#, eg:
int Val;
switch(Val)
case -1:
//val=-1
break;
case 1:
//val=1
break;
default:
//something else
break;
From what I have been trying, it looks like it cannot, then what is the alternative since I need to pass -1
Thanks,
Can a negative value be passed to a switch/case statement in C#, eg:
int Val;
switch(Val)
case -1:
//val=-1
break;
case 1:
//val=1
break;
default:
//something else
break;
From what I have been trying, it looks like it cannot, then what is the alternative since I need to pass -1
Thanks,
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Here is the actual error:
Control cannot fall through from one case label ('case "-1":') to another
Control cannot fall through from one case label ('case "-1":') to another
ASKER
I found out the problem. That was the only case statement where I had missed putting a break statement.
Thanks to all the experts for your time!
Thanks to all the experts for your time!
ASKER
for some reason, the compiler returns the error, cannot pass through case -1:
And whereever I put this piece of code, the error line number always point to the same.