实在找不出原因在哪了,请各位大侠帮忙瞧瞧

    请各位大侠有空帮小弟看看问题到底是出在哪里,故障有两个,第一个是下面那个被调用的函数在return了以后还要在从SetParentNode(familyStr, entity.ParentCategoryId.Value)处按顺序往下执行一次(虽然并没有影响返回的结果);第二个是上面的主函数当中在return result以后,就说result是未被定义的变量,真的不知道是哪里出了问题了,希望各位大侠看看。。。

主函数

string  SetFamilyNode( int  parentCategoryId)
    {
        
try
        {
            
string  result  =  parentCategoryId.ToString();

            
if  ( ! parentCategoryId.Equals( 0 ))
            {
                result 
=  SetParentNode( new  StringBuilder(result), parentCategoryId);
            }

            
return  result;
        }
        
catch  (Exception ex)
        {
            
throw   new  Exception(ex.Message.Trim());
        }
    }
被调用函数
string  SetParentNode(StringBuilder familyStr,  int  infoCategoryId)
    {
        
try
        {
            entity 
=  service.GetByInfoCategoryId(infoCategoryId);
            
if  (entity  !=   null )
            {
                familyStr.Append(
" , "   +  entity.ParentCategoryId.Value.ToString());
                
if  ( ! entity.ParentCategoryId.Value.Equals( 0 ))
                {
                    SetParentNode(familyStr, entity.ParentCategoryId.Value);
                }
            }
            
return  familyStr.ToString();
        }
        
catch  (Exception ex)
        {
            
throw   new  Exception(ex.Message.Trim());
        }
    }
把上面的改成如下就可以了
string  SetParentNode(StringBuilder familyStr,  int  infoCategoryId)
    {
        
try
        {
            InfoCategoryService service 
=   new  InfoCategoryService();
            InfoCategory entity 
=   new  InfoCategory();
            entity 
=  service.GetByInfoCategoryId(infoCategoryId);
            
if  (entity  !=   null )
            {
                familyStr.Append(
" , "   +  entity.ParentCategoryId.Value.ToString());
                
if  ( ! entity.ParentCategoryId.Value.Equals( 0 ))
                {
                    SetParentNode(familyStr, entity.ParentCategoryId.Value);
                }
            }
            
return  familyStr.ToString();
        }
        
catch  (Exception ex)
        {
            
throw   new  Exception(ex.Message.Trim());
        }
    }

转载于:https://www.cnblogs.com/jewleo/archive/2009/11/19/20091119_1.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值