I recently switched from VB to C#. One thing that I noticed was that in C#, I have problems using comparisons as part of the case. I am not sure how to explain it in words, so here is an example of what I am trying to do.
In VB, my code looks like this and works perfectly fine.
Select Case ExamScore
Case Is >= 90
Grade = "A"
Case Is >= 80
Grade = "B"
Case Is >= 70
Grade = "C"
Case Is >= 60
Grade = "D"
Case Else
Grade = "F"
End Select
In C# on the other hand, Visual Studio tells me that ">=" is an invalid expression.
switch (examScore)
{
case >= 90: grade = "A"; break;
case >= 80: grade = "B"; break;
case >= 70: grade = "C"; break;
case >= 60; grade = "D"; break;
default: grade = "F"; break;
}
Am I doing something wrong here, or is it simply not possible to do this in C#?
Thank you very much in advance!