C#检查textbox == textbox

时间:2013-04-12 10:33:14

标签: c# version auto-update

为什么这不起作用:

            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

3 个答案:

答案 0 :(得分:2)

尝试以下可能会对你有帮助..

更改您的代码

FROM:

if (This_Ver.Text == New_Ver.Text)

TO:

if (This_Ver.Text.ToUpper().Trim().Equals(This_Ver.Text.ToUpper().Trim()))

答案 1 :(得分:1)

尝试类似这样的事情

string value1 = This_Ver.Text.Trim();
string value2 = New_Ver.Text.Trim();
if(value1  == value2 )
 {
   //hide your panel
 }
 else
 {
    // code something
 }

如果值匹配则隐藏,否则它将转到else部分,您可以在其中执行某些逻辑代码。

Aslo想了解value1,value2IF Condition

调试时获得的值

答案 2 :(得分:0)

你必须使用(This_Ver.Text.Equals(New_Ver.Text))因为==比较器不起作用。如在Java中,==比较器做对象引用比较。相反,Equals方法比较字符串内容。

祝你好运。