简化此操作的最佳方法是什么(通过方法创建或其他方式): if ((radioButton1.Checked == false) (radioButton2.Checked == false) (radioButton1.Checked == false) ...more similar controls... ((radioButton99.Checked == false))
if ((radioButton1.Checked == false) && (radioButton2.Checked == false) && (radioButton1.Checked == false) && ...more similar controls... && ((radioButton99.Checked == false)) { MessageBox.Show("Please select an option!); }
谢谢您的考虑.对由此造成的任何不便或不满表示歉意.
您可以将所有这些控件放在List中,然后检查是否检查了列表中的任何控件.这可以通过几种方式完成.下面两个例子.使用循环的示例:
bool optionSelected = false; foreach(var control in controls) // the List is in this case called controls { if(control.Checked) { optionSelected = true; } } // Check the boolean
使用System.Linq的示例:
if(!controls.Any(c => c.Checked)) { MessageBox.Show("Please select an option!); }