Is there a way to do the following in one statement?
foreach(CheckBox subset in groupBox_subset.Controls)
if(subset.Checked) { ... }
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Sure:
The
Castcall is required because theControlsproperty only implementsIEnumerable, notIEnumerable<T>, but LINQ basically works on strongly-typed collections. In other words, your existing code is actually closer to:If you want to be able to ignore non-
CheckBoxcontrols, you want theOfTypemethod instead ofCastin the top snippet: