public bool Example_bool (bool state)
{
if (x == state)
{
button.Enabled = false;
}
else
{
button.Enabled = true;
}
}
为什么会出现错误?我想在某个条件运行时停用按钮,如果没有则应该启用按钮。
你有一个方法,希望返回一个bool
,这个方法不返回任何东西。如果用bool
替换void
,错误就会消失。
public void Example_bool (bool state)
{
if (x == state)
{
button.Enabled = false;
}
else
{
button.Enabled = true;
}
}
或者更紧凑:
public void Example_bool (bool state)
{
button.Enabled = x != state;
}
看看你的陈述。 1.什么是x在哪里定义?既然你要通过布尔,为什么不这样简化呢?
public void Example_bool (bool state)
{
button.Enabled = state;
}