非常自我解释。如果在checkedListBox中选中了某个选项,我想更改一个字符串。选中其他选项后再次更改。我会说if语句会起作用但是我如何在if语句中这样做,以便其他对象可以使用该字符串?
答案 0 :(得分:0)
您可以使字符串成为常量,并在checkedListBox的SelectedIndexChanged事件中为其赋值。像(伪代码)的东西:
private readonly String clbResponse = String.Empty;
. . .
protected void clb_SelectedIndexChanged(object sender, eventargs e)
{
int indexSelected = clb.SelectedIndex;
case (indexSelected)
0:
clbResponse = "index 0 was selected";
break;
1:
clbResponse = "index 0 was selected";
break;
. . .
default
break;
}