使用yield进行递归

public partial class Controls_SectionIndex : System.Web.UI.UserControl
{
    private NBearLite.Database Db = NBearLite.Database.Default;

    protected void Page_Load(object sender, EventArgs e)
    {
        int sectionType = Convert.ToInt32(Request.QueryString["sectiontype"]);
        rep.DataSource = ListIndex(sectionType, 0);
        rep.DataBind();

    }


    public IEnumerable<GHSection> ListIndex(int sectionType, int parentID)
    {
        List<SqlGHSection> list = Db.Select(Tables.GHSection)
            .Where(Tables.GHSection.SectionType == sectionType && Tables.GHSection.ParentID == parentID)
            .OrderBy(Tables.GHSection.ID.Asc)
            .ToList<SqlGHSection>();
        foreach (GHSection node in list)
        {
            yield return node;
            foreach (GHSection node3 in ListIndex(sectionType, node.ID))
            {
                yield return node3;
            }

        }
    }
}

posted @ 2008-06-20 11:18 菜无罪1 阅读(50) 评论(0)  编辑 收藏 所属分类: asp.net2.0

标题  
姓名  
主页
Email (博主才能看到) 
验证码 *  看不清,换一张 [登录][注册]
内容(请不要发表任何与政治相关的内容)  
  登录  使用高级评论  新用户注册  返回页首  恢复上次提交      


相关链接: