lundi 25 janvier 2021

How to simplify this test condition on strings: if one is entered, the other must be entered too?

I have written the following condition expression. It works just fine...I am trying to figure out/learn a clever way to decrease the amount of code. Perhaps using some c# Boolean logical operators in an advanced manner.

if ((!String.IsNullOrWhiteSpace(ProxyServer.ParameterValue) &&
     String.IsNullOrWhiteSpace(ProxyPort.ParameterValue))
    || (!String.IsNullOrWhiteSpace(ProxyPort.ParameterValue) &&
        String.IsNullOrWhiteSpace(ProxyServer.ParameterValue)))
{
    result = "If one is present, both must be entered for Proxy Server, Proxy Port.";
}

Aucun commentaire:

Enregistrer un commentaire