在我的设计中有几个radiobutton  各个按钮的Text都有显示内容   
  本人想用switch 语句
 switch (test.studentAnswers[questionindex])
            {
                case "A":
                    radA.Checked = true;
                    answer = "A";
                    break;
                case "B":
                    radB.Checked = true;
                    answer = "B";
                    break;
                case "C":
                    radC.Checked = true;
                    answer = "C";
                    break;
           
                default:
                    radA.Checked = false;
                    radB.Checked = false;
                    radC.Checked = false;
                    break;
            }test.studentAnswers[questionindex] 是存放radn.Text的内容
不知怎样将radioButton中的内容转换为我所要的A、B、C
还请各位帮忙解决 谢谢!

解决方案 »

  1.   

    首先,你的radn.Text的内容要和A,B,C之间有一定的关系;
    其次,在那个switch语句中就能实现转换;当然,你可以写一个方法来转换,或者用hash table或者更复杂的方式来处理。
      

  2.   

    在这些代码之前  每个按钮都有
                     this.radA.Text = string.Format("A:{0}", rd["option"]);
                    test.studentAnswers[questionindex]=this.radA.Text;
    我想将 test.studentAnswers[questionindex]中的的内容用switch语句来判断 但是 test.studentAnswers[questionindex]里面的具体内容我不清楚 
    如今想用A、B、C来代替test.studentAnswers[questionindex]
    不知这样说 你清楚了吗?
      

  3.   

    之前 的内容和A、B、C有关  请看 3楼我的回复
      

  4.   

    看你的代码,你已经这样做了。 answer会根据你传入的 test.studentAnswers[questionindex] 值而改变
      

  5.   

    如果你是想把test.studentAnswers[questionindex]这个数组内的值赋值给answer,
    那不应该用switch做。 而需要用for(int i= 0; i <=questionindex;i++) 内完成赋值
      

  6.   


    answer 是用来存放选项的 即A、B、C
    而我想把test.studentAnswers[questionindex]的值转换为相应的A、B、C存放在数据库中  不是将test.studentAnswers[questionindex]的内容存放在数据库中  因为是radioButton 是用来做选想的 我用了几个radioButton 想判断是否选中相应的radioButton 然后再将选中的存入数据库中
      

  7.   


    其实你test.studentAnswers[questionindex]的值都是来自于 radA.Text;
    那你应该将switch中 case 部分改变一下, case "A" 应该是 case radA.Text的值