if (this.radioButton2.Checked)
            {
                this.skinEngine1.SkinFile = "EmeraldColor2.ssk";
                return;
            }
            else if (this.radioButton3.Checked)            {
                this.skinEngine1.SkinFile = "MidsummerColor2.ssk";
                return;
            }
            
请问下 如果要转成 switch的话怎么写。 radiobutton 没有 selectvalue属性啊。。

解决方案 »

  1.   

    你是判断它是不是被选中...
    用switch的话不如直接用if else呢  foreach (RadioButton rad in this.Controls)
                {
                    switch (rad.Name)
                    {
                        case "radioButton2":
                            if (radioButton2.Checked)
                            { this.skinEngine1.SkinFile = "EmeraldColor2.ssk";
                            }
                            break;
                        case "radioButton3":                }
                }
      

  2.   

    sting[] skins=new sting []{"",""EmeraldColor2.ssk","MidsummerColor2.ssk"};
    radioButton1.Tag=0;
    radioButton2.Tag=1;
    radioButton3.Tag=2;                foreach (Control mycontrol in this.Controls)
                    {
                        if (mycontrol.GetType() == typeof(RadioButton))
                        {
                            RadioButton myradio = mycontrol as RadioButton;                        
                            int index =(int) myradio.Tag;
                            if (myradio.Checked == true)
                            {
                                this.skinEngine1.SkinFile=skins[index];
                                break;
                            }
                        }
                    }
     
      

  3.   

    swich 的执行效率可没有if else快.
      

  4.   

    radiobutton 没有 selectvalue属性啊
    =========
    用RadioButtonList即可,楼主的例子无须使用switch
      

  5.   

    switch与if并不能总是可以相互转换!
      

  6.   


    RadioButton rbtn = new RadioButton();
    rbtn = (RadioButton)(this.rbtn1.Checked ? this.rbtn1 : (this.rbtn2.Checked ? this.rbtn2 : null));
    switch(rbtn.Text)
    {
          case "apple":this.txtFruit.Text = this.rbtn1.Text;
                  break;
          case "pear":this.txtFruit.Text = this.rbtn2.Text;
                  break;
          default:this.txtFruit.Text = "You choose nothing.";
                  break;
    }