Problem with If and TextBox - C #

1

My if does not evaluate correctly, I want you to verify that the textbox are not empty or that textbox1 or textbox2 is not "var" , otherwise mark error.

if (textbox1 != "" || textbox1 != "var" && textbox2 != "" || textbox2 != "var" && comboBox1 !=""){        
    MessageBox.Show("Mandar datos");

    } else {
        MessageBox.Show("Error");
    }
}
    
asked by Ramon Soto Vega 15.05.2017 в 19:37
source

1 answer

3

the problem is in the order of precedence of the operators

& amp; it is evaluated first and then evaluated ||

if you have:

if (v1 != "" || v1 != "var" && v2 != "" || v2 != "var" && v3 !="")

is evaluated as follows:

if (v1 != "" || (v1 != "var" && v2 != "") || (v2 != "var" && v3 !=""))

and I guess you want me to evaluate it like this:

if ((v1 != "" || v1 != "var") && (v2 != "" || v2 != "var") && (v3 !=""))

If you are not sure of the order of precedence use parentheses to make sure.

    
answered by 15.05.2017 / 19:49
source