public static string RadioList(System.Web.UI.WebControls.RadioButtonList RadioList)
{
            for (int x = 0; x <= RadioList.Items.Count - 1; x++) 

if (RadioList.Items[x].Selected) 

string RadioBody= RadioList.Items[x].Value; 
return RadioBody;

}
}
提示:并非所有代码路径都有返回值

解决方案 »

  1.   

    public static string RadioList(System.Web.UI.WebControls.RadioButtonList RadioList)
    {
        string RadioBody = "";
        for (int x = 0; x <= RadioList.Items.Count - 1; x++) 

    if (RadioList.Items[x].Selected) 

    RadioBody= RadioList.Items[x].Value;  } 
    }
         return RadioBody;}
      

  2.   

    public static string RadioList(System.Web.UI.WebControls.RadioButtonList RadioList)
    {
             string RadioBody = "";
             for (int x = 0; x <= RadioList.Items.Count - 1; x++) 

    if (RadioList.Items[x].Selected) 

    RadioBody= RadioList.Items[x].Value;
                               break;


    return RadioBody;
    }
      

  3.   

    你应该把return RadioBody;放在FOR循环的外面,以前我也碰到过这样的问题。
      

  4.   

    嗯,hchxxzx(NET?摸到一点门槛) 说得对,就是这个原因
      

  5.   

    如果你的for循环根本不执行那不是就没有返回值了
    这个所以你最后有个默认的返回值
      

  6.   

    提示:并非所有代码路径都有返回值
    这个提示的原因是,如果一个方法有返回值的情况下,编译程序会检验不管程序如何执行都要有返回值的。以你的程序为例,如果if执行后为FALSE。则return将不执行,所以你的方法就没有返回值。编译是不会通过的。