我有六个单选框,text属性分别是:A,B,C,D,E,F,如何将其传递给switch语句的表达式啊~~~
switch (radius)
           {               case A:
                   atmosphereStability = 1;    //此时的atmosphereStability的值1、2、3、4、5、6对应大气稳定度等级A、B、C、D、E、F
               case B:
                   atmosphereStability = 2;
               case C:
                   atmosphereStability = 3;
               case D:
                   atmosphereStability = 4;
               case E:
                   atmosphereStability = 5;
               case F:
                   atmosphereStability = 6;
           }       private void radioButton2_CheckedChanged(object sender, EventArgs e)
       {
           RadioButton radioButton2 = new RadioButton();
           string radius = Convert.ToString(radioButton2.Text);  //将radioButton的Text值赋给radius变量
       }

解决方案 »

  1.   

    if (radio1.Value == 1)
        atmosphereStability = 1;
    if (...)
        ...
      

  2.   

    RadioButton[] radios = new RadioButton[]{radioButton1,radioButton2,radioButton3,radioButton4,radioButton5,radioButton6};
    for(int i=0;i<radios.Length;i++)
    {
        if(radios[i].Checked) 
        {
            atmosphereStability = i;
            break;
        }
    }
      

  3.   

    难道用if有什么不好?你怎么不突发奇想用 for 语句实现来,我来写一个:foreach (Control c in this.Controls)
    {
        if (c.GetType() == typeof(RadioButton)
            if (RadioButton)c.Value = 1) {
                atmosphereStability = (int)((char)c.Text) - 64;
                break;
            }
    }无聊。
      

  4.   

    何须switch:
    atmosphereStability =radius[0]-'A'+1;
    另外,这里:string radius = radioButton2.Text; //将radioButton的Text值赋给radius变量string赋给string类型的变量无须Convert。