English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

How can I combine two conditions with AND to get this...
here is the code.


{
if (user.Text = "moe" & pass.Text = "2123812812")
Response.Redirect("Default2.aspx?user=" + user.Text);
else
Response.Redirect("default3.aspx");
}


It generates an error with & operand... whats right to code?

2006-10-18 14:54:58 · 2 answers · asked by Doublethink..!! 1 in Computers & Internet Programming & Design

Ok I tried with &&....
the same error generated... which is
"Operator '&&' cannot be applied to operands of type 'String' and 'String'."

Any idea?

2006-10-18 14:59:16 · update #1

thanks anyways guys... the problem was i used the assignment operator "=".. i should have used "==". it worked now.

2006-10-18 15:18:09 · update #2

2 answers

I am not familiar with C# but most languages it's a double ampersand if (this=true && that=true)

ALSO

Just noticed your brackets are in the wrong place - try this:


if (user.Text = "moe" && pass.Text = "2123812812")
{
Response.Redirect("Default2.as... + user.Text);
}
else
{
Response.Redirect("default3.as...
}

2006-10-18 14:57:05 · answer #1 · answered by teef_au 6 · 1 0

It should be this the right code! It is important that when doing an If statement you cannot check more than one thing as you did. You have to do as follows:

if ((user.Text == "moe") && (pass.Text =""2123812812"))
{
Response.Redirect("Default2.as.... + user.Text);
}
else
{
Response.Redirect("defualt3.as...");
}

2006-10-21 04:17:18 · answer #2 · answered by Dan 3 · 0 0

fedest.com, questions and answers