[英]How to check two conditions in an IF statement in windows phone 7 application using c#?
I am building an application for windows phone 7 where i have a form and i need to validate two conditions here. 我正在为Windows Phone 7构建一个应用程序,其中有一个表格,我需要在这里验证两个条件。 The condition is that the textbox shouldnot contain null value and also the value should not be equal to *Name.
条件是文本框不应包含空值,并且该值也不应等于* Name。
if(name.Text == String.Empty)
{
MessageBox.Show("Please Enter the name");
name.Focus();
return false;
}
Please help me to put the 2nd condition here 请帮我把第二个条件放在这里
You want to use the &&
operator, something like this 您想使用
&&
运算符,像这样
if (name.Text == String.Empty && name.Text != *Name)
{
MessageBox.Show("Please Enter the name");
name.Focus();
return false;
}
you need OR condition like below 您需要如下所示的OR条件
if (string.IsNullOrEmpty(name.Text) || name.Text == "Name")
{
MessageBox.Show("Please Enter the name");
name.Focus();
return false;
}
if ((name.Text == String.Empty) || (name.Text == "Name"))
{
MessageBox.Show("Please Enter the name");
name.Focus();
return false;
}
if (name.Text == String.Empty)
{
MessageBox.Show("Please Enter the name");
name.Focus();
return false;
}
else
{
if(name.Text == "Name"){
MessageBox.Show("Your error message");
name.Focus();
return false;
}
}
try this: 尝试这个:
if (name.Text == null && name.Text != "Name")
{
MessageBox.Show("Please Enter the name");
name.Focus();
return false;
}
if ((name.Text == String.Empty) || (name.Text == "Name"))
{
MessageBox.Show("Please Enter the name");
name.Focus();
return false;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.