C# Check if textbox == textbox
本文关键字:textbox if Check | 更新日期: 2023-09-27 18:08:43
为什么不工作:
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;
}
}
我正在尝试比较新版本和当前运行的版本。当文本框中不包含相同版本时,应该打开更新面板。
但是它不工作。它总是打开更新面板。
编辑:value: This_Ver。文本:V1.1.13.1
value: New_Ver。文本:V1.1.13.1
试试下面的方法,也许会对你有帮助。
修改代码
:
if (This_Ver.Text == New_Ver.Text)
:
if (This_Ver.Text.ToUpper().Trim().Equals(This_Ver.Text.ToUpper().Trim()))
试试这样
string value1 = This_Ver.Text.Trim();
string value2 = New_Ver.Text.Trim();
if(value1 == value2 )
{
//hide your panel
}
else
{
// code something
}
如果value匹配,则隐藏,否则将转到else
部分,在那里执行一些逻辑代码。
还想知道当调试在IF Condition
value1,value2
中得到的值是什么您必须使用(This_Ver.Text.Equals(New_Ver.Text)),因为== comparator将不起作用。与Java中一样,== comparator执行对象引用比较。与此相反,Equals方法比较字符串的内容。
好运。