Sorry to ask this as I thought I knew the answer, I want to exit the program if userName is greater than 4 characters or userName is not an account called student. However this even if the userName is only 3 characters and is not student I'm still hitting Application.Exit. What am I doing wrong?
if (userName.Length > 4 | userName != "student")
{
Application.Exit();
}
Shame on me :-(
While you should use || instead of |, they will give the same result in this situation. Despite the upvoting of the other answers, changing | to || will not solve your problem.
Your real problem is that the conditions you want to check for will always be true. Either your userName is not student, or it is student and then it is also longer than 4 characters.
When you have a username that is only 3 characters it is not equal to student, therefore the program quits.
From your description of what you expect, I think you mean this:
if (userName.Length > 4 && userName != "student")
{
Application.Exit();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With