首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

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

2012-01-09 
关于递归返回值的问题publicstringGetStringText(TreeNodenode){stringstr if(nodenull)returnstre

关于递归返回值的问题
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想要实现的?

热点排行