快速找出被選中radioButton(會linQ就很簡單,別在foreach了)

快速找出被選中radioButton(會linQ就很簡單,別在foreach了)

image

1. [畫面上簡單丟3個radioButton、1個Button(Selected RadioButton)]

2.為”Selected RadioButton”,寫上

 
   1:   RadioButton selectedRadio = this.Controls.OfType<RadioButton>().Where(q => q.Checked == true).First<RadioButton>();
   2:   if (selectedRadio != null)
   3:       MessageBox.Show(selectedRadio.Text);

 

image image