how loop through multiple checkbox in C#

前端 未结 6 1053
后悔当初
后悔当初 2021-01-14 00:06

I have 100 checkbox in a winfrom. Their name is sequential like checkbox1,checkbox2 etc. I have a submit button in my winform. After clicking the submitting button, it check

6条回答
  •  攒了一身酷
    2021-01-14 00:34

    There is LINQ method OfType. Why not use it to get rid of manual type testing and casting?

    foreach (var ctrl in panel.Controls.OfType().Where(x => x.IsChecked)
    {
        // ....
    }
    

提交回复
热议问题