我做错了什么;如果“;陈述
本文关键字:如果 陈述 什么 错了 | 更新日期: 2023-09-27 18:25:11
因此,我有两个if语句,通过手机提供的DeviceName来检测您是否使用HTC 8X或8S。问题是,它似乎忽略了"如果",只运行所有的代码。。。例如,我放置了一行代码(用于调试),在运行每个部分后显示一个消息框,但两个消息框都显示了,而不仅仅是8X消息框,表明它正确检测到我在8X上运行该应用程序。这可能只是一个"愚蠢的错误",但我不明白我。。。
if (Microsoft.Phone.Info.DeviceStatus.DeviceName == "Windows Phone 8X by HTC") ;
{
//Debugging MSG
MessageBox.Show("8X Works")
//Rating
MainScore.Text = "6.1";
//Subscores
Processor.Text = "5.2";
RAM.Text = "6.5";
Graphics.Text = "8.0";
HardDisk.Text = "5.1";
//Issues
Issues.Text = "0 ISSUES FOUND";
}
if (Microsoft.Phone.Info.DeviceStatus.DeviceName == "Windows Phone 8S by HTC");
{
//Debugging MSG
MessageBox.Show("8S Works")
//Rating
MainScore.Text = "2.8";
//Subscores
Processor.Text = "3.2";
RAM.Text = "2.4";
Graphics.Text = "4.0";
HardDisk.Text = "1.9";
//Issues
Issues.Text = "0 ISSUES FOUND";
}
在每次IF测试后立即删除分号。分号之后的代码块每次都是无条件运行的。
由于分号的存在,以下是编译器查看代码的方式
(查找/* */
注释)
if (Microsoft.Phone.Info.DeviceStatus.DeviceName == "Windows Phone 8X by HTC")
/* DO NOTHING */;
/* Regular, Unconditional Code */
{
//Debugging MSG
MessageBox.Show("8X Works")
//Rating
MainScore.Text = "6.1";
//Subscores
Processor.Text = "5.2";
RAM.Text = "6.5";
Graphics.Text = "8.0";
HardDisk.Text = "5.1";
//Issues
Issues.Text = "0 ISSUES FOUND";
}
if (Microsoft.Phone.Info.DeviceStatus.DeviceName == "Windows Phone 8S by HTC")
/* DO NOTHING */;
/* Regular Unconditional code */
{
//Debugging MSG
MessageBox.Show("8S Works")
//Rating
MainScore.Text = "2.8";
//Subscores
Processor.Text = "3.2";
RAM.Text = "2.4";
Graphics.Text = "4.0";
HardDisk.Text = "1.9";
//Issues
Issues.Text = "0 ISSUES FOUND";
}