If the requirement is to count the
CheckBoxes
which are
Checked
, then the following LINQ query can be used
for(int i=0; i< 10; i++){
CheckBox chkBox = new CheckBox();
if (i % 2==0)
chkBox.Checked = true;
Controls.Add(chkBox);
}
Controls.Add(new TextBox());
Controls.Add(new Button());
int selectedCheckBoxesCount = Controls.OfType<CheckBox>()
.Count (cb => cb.Checked);