在 C# WinForms 我有几个单选按钮,在我的代码中它看起来像这样:
public void Adjust_id()
{
if (radio_button_0.Checked)
(database.Record).active_id = 0;
else if (radio_button_1.Checked)
(database.Record).active_id = 1;
else if (radio_button_2.Checked)
(database.Record).active_id = 2;
else if (radio_button_3.Checked)
(database.Record).active_id = 3;
else if (radio_button_4.Checked)
(database.Record).active_id = 4;
else if (radio_button_5.Checked)
(database.Record).active_id = 5;
else if (radio_button_6.Checked)
(database.Record).active_id = 6;
else if (radio_button_7.Checked)
(database.Record).active_id = 7;
else if (radio_button_8.Checked)
(database.Record).active_id = 8;
else if (radio_button_9.Checked)
(database.Record).active_id = 9;
else if (radio_button_A.Checked)
(database.Record).active_id = 10;
else if (radio_button_B.Checked)
(database.Record).active_id = 11;
else if (radio_button_C.Checked)
(database.Record).active_id = 12;
else if (radio_button_D.Checked)
(database.Record).active_id = 13;
else if (radio_button_E.Checked)
(database.Record).active_id = 14;
else if (radio_button_F.Checked)
(database.Record).active_id = 15;
}
在我看来,这很丑陋。有没有更好的方法来缩短此代码?我不知道如何遍历那些单选按钮...