读书人

关于递归返回值的有关问题

发布时间: 2012-01-09 21:05:42 作者: rapoo

关于递归返回值的问题
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);
}
}
总是报‘并非所有的代码路径都返回值’
大家帮我看看

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

读书人网 >C#

热点推荐