无意引用的警告比较 c#

Warning comparision of unintentional references c#

首先感谢阅读。 我正在 Visual Studio 2015 - C# 开发一个项目,我收到了这个警告

CS0252 Possible comparison of unintentional references; To get a comparison of values, convert the left side to type 'string'

我已经查看了 Microsoft 网站,但我不明白为什么会出现警告。

警告所在行:

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
     if (comboBox1.SelectedItem == "Por ID Cliente")
     {
            txtBoxID.Visible = true;
            lblID.Visible = true;
        lblID.Text = "ID Cliente:";
     }
}

我这样做是为了根据在 comboBox1 上选择的项目显示标签和文本框。 当我尝试编译时它工作!但我想删除警告

您正在尝试以字符串形式访问对象。您应该使用 comboBox1.SelectedItem.Value 或 comboBox1.SelectedValue.

你应该检查:

if (comboBox1.Items.FindByValue("value") != null) {
    comboBox1.SelectedValue = "value";
}