字符串怎么判断IF

来源:百度知道 编辑:UC知道 时间:2024/06/17 02:56:44
if (Value4 == "禁用")
{
radioButton3.Checked = true;

}
else
{
radioButton4.Checked = true;

}

这样打每次都判定是ELSE后面的

我刚把你的代码放到程序上试验了一下,是对的,
你的Value4是从文本框接过来的吗?如果是最好这样写
string Value4=textBox1.Text;
if(Value4.Trim() == "禁用")
{
radioButton13.Checked = true;
}
else
{
radioButton4.Checked = true;

}

也可以这样写
string Value4 = textBox1.Text;
if (Value4.Trim().Equals("禁用"))
{
radioButton1.Checked = true;
}
else
{
radioButton2.Checked = true;

}

你用断点调试下。。看看Value4 传入的值是否为"禁用"。。如果不是当然是执行else{}

value4.Equles("禁用")