方法体中定义递归方法

public List GetData(IDbConnection connection)
{
    Func, List> DiguiChild = null;
    DiguiChild = new Func, List>((pid, plist) =>
    {
        List childlist = new List();
        foreach (var menu in plist)
        {
            if (menu.ParentId != null && menu.ParentId > 0)
            {
                if (menu.ParentId == pid)
                {
                    childlist.Add(menu);
                }
            }
        }
        foreach (var menu in childlist)
        {
            menu.Child = DiguiChild (menu.Id, plist);
        }
        return childlist;
    });
    Func,List> Genter = new Func,List>((levellist) =>
    {        
        var result = levellist.Where(x => x.ParentId==null).ToList();
        foreach (var c in result)
        {
            c.Child = DiguiChild (c.Id, levellist);
        }
        return result;
    });
}

你可能感兴趣的:(c#,递归算法)