为什么这不起作用:
if (This_Ver.Text == New_Ver.Text)
{
MAIN_PANEL.Visible = true;
}
else if (This_Ver.Text != New_Ver.Text)
{
DialogResult dialogResult = MessageBox.Show("An update has been found!" + Environment.NewLine + "Would you like to download and install it?", "Update found!", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
if (dialogResult == DialogResult.Yes)
{
MAIN_PANEL.Visible = false;
UPDATE_PANEL.Visible = true;
USERNAME_TEXT.Enabled = false;
PASSWORD_TEXT.Enabled = false;
LOGIN_BUTTON.Enabled = false;
MAIN_PANEL.Visible = false;
UPDATE_NOW_BUTTON.Enabled = true;
}
else if (dialogResult == DialogResult.No)
{
UPDATE_NOW_BUTTON.Enabled = true;
MAIN_PANEL.Visible = true;
}
}我正在尝试比较新版本和当前运行的版本。当文本框不包含相同版本时,它应该会打开更新程序面板。
但它不起作用。它总是打开更新程序面板。
编辑:
取值: This_Ver.Text : V1.1.13.1
取值: New_Ver.Text : V1.1.13.1
发布于 2013-04-12 18:52:44
尝试如下可能会对你有所帮助..
更改您的代码
来自:的
if (This_Ver.Text == New_Ver.Text)TO :
if (This_Ver.Text.ToUpper().Trim().Equals(This_Ver.Text.ToUpper().Trim()))发布于 2013-04-12 18:40:07
试试这样的东西
string value1 = This_Ver.Text.Trim();
string value2 = New_Ver.Text.Trim();
if(value1 == value2 )
{
//hide your panel
}
else
{
// code something
}如果值匹配,它将被隐藏,否则它将转到else部分,在那里您可以执行一些逻辑代码。
我还想知道当在IF Condition上调试时,你在value1,value2中得到了什么值
发布于 2013-04-12 18:40:03
您必须使用(This_Ver.Text.Equals(New_Ver.Text)),因为==比较器将不工作。与在Java语言中一样,==比较器执行对象引用比较。相反,Equals方法比较字符串内容。
祝好运。
https://stackoverflow.com/questions/15969083
复制相似问题