0

I'm trying to compare two strings using this code in a switch statement:

case "medStepOne":
WebEligibilityMedFirst.SelectOptions(p0);
    if (!p0.Equals("failOne") || !p0.Equals("failTwo") || !p0.Equals("failThree") || !p0.Equals("failFour"))
       {
           WebEligibilityMedSecond.SelectOptions(p0);
        }
break;

The string is definitely "failOne" so I believe that the code should bypass the if statement but it does not.

2 Answers 2

0

Embarrassingly, I saw the problem pretty much as soon as I'd re-read it to make sure I'd asked it correctly. I need && instead of ||

0

t appears that the issue is with the way the if condition is written. The condition !p0.Equals("failOne") || !p0.Equals("failTwo") || !p0.Equals("failThree") || !p0.Equals("failFour") is always true, even when the value of p0 is "failOne".

You can modify the condition as follows to achieve the expected behavior:

if (!p0.Equals("failOne") && !p0.Equals("failTwo") && !p0.Equals("failThree") && !p0.Equals("failFour"))
{
    WebEligibilityMedSecond.SelectOptions(p0);
}

This condition will evaluate to true only if p0 is not equal to "failOne", "failTwo", "failThree", or "failFour".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.