+ 2
How you refer to data in a range with switch statement in C#?
I'm writing a program on C# to grade students results but I can't use switch statement to refer to a range let's say like 80-100 which should get a grade A. Just give me the format of the code specifically on switch statement.
2 odpowiedzi
+ 4
Yes, use if instead. I don't know c#, but in all the other ones I know it would be much easier just to do: if(score>=80){grade = A};
0
It is not possible to specify a range in switch case statements because the main purpose of switch statements is to comparison between constants. Use if else ladder instead. And if u want to use switch only then write complete range in cases. Example:
Case 100:
Case 99:
Case 98:
Case 80:
Break;
This is a lengthy process, and useless. So use if else only.