I want to use one command which will contain two “textboxes.Text” in one “If”. I mean when I did this command :
If (textBox1.Text == ("admin")) + (textBox2.Text == ("admin)) or this If (textBox1.Text == ("admin) , textBox2.Text == admin)) it isn’t right.
The main code is:
private void Label_Click(object sender, EventArgs e)
{
if (textBox2.Text == ("admin")) + (textBox1.Text == ("admin"))
{
Label.Text = "right";
}
else
{
Label.Text = "wrong";
errorProvider1.SetError(errorprovider, "Wrong Username or Password");
}
Namely the thing I wanted to do is if one of two textboxes is wrong the label will show that the password or the username is wrong … any ideas ?
The syntax for an
ifstatement is:Your current code is:
… which is treating
textBox2.Text == ("admin")as the condition, and then trying to use+ (textBox1.Text == ("admin"))as the body, which isn’t valid. The problems are:Additionally, you’re putting parentheses around string literals for no obvious reason, reducing readability. So what you really want is:
Note that other answers have suggested using
||instead of&&– that would be an OR condition, which would show a result of “Right” if either of the textboxes had a value ofadmin. I suspect that’s not what you want.