public string GetStringText(TreeNode node)
{
string str = ""; if (node == null)
return str;
else
{
str = node.Text.Trim() +"<--" + str; if (node.Parent != null)
{
this.GetStringText(node.Parent);
}
else
return str.Substring(0,str.Length-3);
}
}
总是报‘并非所有的代码路径都返回值’
大家帮我看看

解决方案 »

  1.   

    主要是这句没有返回值
    if (node.Parent != null)
    {
    this.GetStringText(node.Parent);
    }
      

  2.   

    改成while(node.Parent != null)
      

  3.   

    在方法最后,也就是在最后一个“}”前面加上return str;看下
      

  4.   

    return this.GetStringText(node.Parent);
      

  5.   

    public string GetStringText(TreeNode node)
        {
            if (node.Parent == null)
                return node.Text.Trim();
            else
            {
                return node.Text.Trim() + "<--" + this.GetStringText(node.Parent);
            }
        }
       //是否为LZ想要实现的?
      

  6.   

    if (node.Parent != null)
    {
    return this.GetStringText(node.Parent);
    }
      

  7.   

    string str = "";        if (node == null)
                return str;
            else
            {
                str = node.Text.Trim() + "<--" + str;            if (node.Parent != null)
                {
                    this.GetStringText(node.Parent);
                    //add
                    return "xxx";
                }
                else
                    return str.Substring(0, str.Length - 3);
            }