我有以下代码,它将布尔列表作为参数,然后通过单独验证列表来设置每个检查列表的检查状态。
有没有更有效的方法来编写以下代码?例如,通过使用循环?
public PointCtrlRowSelectionForm(List<Boolean> checkList, PointCtrlForm form, string title)
{
InitializeComponent();
this.form = form;
this.Text = title;
if (checkList[0] == true)
{
checkBox1.Checked = true;
checkBox1.CheckState = CheckState.Checked;
}
if (checkList[1] == true)
{
checkBox2.Checked = true;
checkBox3.CheckState = CheckState.Checked;
}
if (checkList[2] == true)
{
checkBox3.Checked = true;
checkBox3.CheckState = CheckState.Checked;
}
if (checkList[3] == true)
{
checkBox4.Checked = true;
checkBox4.CheckState = CheckState.Checked;
}
if (checkList[4] == true)
{
checkBox5.Checked = true;
checkBox5.CheckState = CheckState.Checked;
}
if (checkList[5] == true)
{
checkBox6.Checked = true;
checkBox6.CheckState = CheckState.Checked;
}
}