I'm making a Windows Form Application with C#.
One of my forms contains 5 group boxes, each containing 6 checkboxes inside. I need to count all the checked checkboxes.
At the moment I have coded it as follows:
int NumOfRacks1 = groupBoxPace.Controls.OfType<CheckBox>()
.Count(cb => cb.Checked);
However I would have to repeat the above 5 times and then add all the variables together to get an answer. I'm sure there is a smarter way to do this which cuts down the code.
I tried to combine three of them as follows:
var allRacks = groupBoxSamsung.Controls.OfType<CheckBox>().Concat(groupBoxPace.Controls.OfType<CheckBox>().Concat(groupBox780.Controls.OfType<CheckBox>()));
But this didn't work as expected.
Does anyone know of a way to achieve this?