我正在尝试创建一个程序,用户输入两个MD5哈希值,然后单击一个按钮来验证它们是否匹配。我尝试了以下操作,但它始终返回else
:
// I skiped the Initialize Component() block for this post.
private void verifyButton1_Click(object sender, EventArgs e)
{
if (textHash1 == textHash2)
{
MessageBox.Show("The hashes match");
}
else MessageBox.Show("The hashes do not match");
}
此代码始终返回else语句
答案 0 :(得分:4)
假设textHash1
和textHash2
是文本框..这不起作用:
if (textHash1 == textHash2)
那是因为你正在比较控件..它们是完全不同的控件(两个文本框都是..但不同的引用)。
您想要比较他们的Text
属性:
if (textHash1.Text == textHash2.Text)