如何在C#中检查字符串是否匹配

时间:2013-09-22 22:34:08

标签: c# string md5 matching

我正在尝试创建一个程序,用户输入两个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语句

1 个答案:

答案 0 :(得分:4)

假设textHash1textHash2是文本框..这不起作用:

if (textHash1 == textHash2)

那是因为你正在比较控件..它们是完全不同的控件(两个文本框都是..但不同的引用)。

您想要比较他们的Text属性:

if (textHash1.Text == textHash2.Text)
相关问题