简体   繁体   English

如何使用C#在Windows Phone 7应用程序中检查IF语句中的两个条件?

[英]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.

相关问题 如何检查Windows Phone 7和C#中两个图像的来源是否相同? - how to check if sources of two images are same in Windows Phone 7 and C#? C#,Windows Phone 7,使用if-else语句检查显示的页面 - C#, Windows Phone 7, Using if-else statement to check which page is displayed C# windows手机6应用到windows手机7 - C# windows mobile 6 application to windows phone 7 使用C#的Windows Phone应用程序中的文件大小限制 - File size limit in Windows Phone application using C# 使用C#在Windows Phone应用程序中计数计时器 - Count up timer in windows phone application using c# 如何在C#Windows Phone中检查和更改名称按钮 - How to check and change name button in C# Windows Phone 如何打开本机应用程序以捕获视频,然后使用C#在Windows Phone 8中捕获后返回我的应用程序? - How to open the native application to capture a video then return to my app once captured in Windows Phone 8 using C#? 如何使用C#在Windows Phone 7应用程序中重置单选按钮的值 - how to reset the value of a radio button in windows phone 7 application using c# 如何在C#中更改Windows Phone 8应用程序的StartPage - How To Change The StartPage Of The Windows Phone 8 Application In C# 如何在c#windows phone 8.1应用程序中写入excel文件? - how to write into the excel file in c# windows phone 8.1 application?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM