简体   繁体   中英

C#: If-Else Troubles

I have an issue with my if else statement to where it will only display the else output and not the if output.

default:
    if (GradeVar >= 10) {
        Console.WriteLine("That grade is a perfect score. Well done!");
    } else {
        Console.WriteLine("That grade is not passing.");
    }
    break;

Here's the specific code I am talking about; its for a program to display certain messages for grades.

The Simple Answer

GradeVar is always less than or equal to 9 .


However, we need a minimal, but complete and verifiable example in order to truly understand what is going wrong. So far we can tell that you're most likely in a switch structure, and probably inside either a method or a loop in which GradeVar is a parameter, local variable, or property. It would be a good idea to revise your question and include the following:

  • Where GradeVar is declared.
  • Anywhere GradeVar 's value is modified, prior to the location in code you've already supplied.
  • Any additional parameters, local variables, or properties that assist in the modification of GradeVar .
  • Anything else we may need to reproduce the issue at hand.

I hope this helps you get the answer you need, and wish you the best of luck in your endeavors.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM