C# 反向递归,讲树形数据结构转换为普通list

C# 反向递归,讲树形数据结构转换为普通list
/// <summary>
        /// 将父子级数据结构转换为普通list
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        public static List<UniWater_MenuInfo> GetMenuInfoList(List<UniWater_MenuInfo> list)
        {
            List<UniWater_MenuInfo> Resultlist = new List<UniWater_MenuInfo>();
            foreach (var item in list)
            {
                OperationChildData(Resultlist, item);
                Resultlist.Add(item);
            }
            return Resultlist;
        }
        /// <summary>
        /// 递归子级数据
        /// </summary>
        /// <param name="treeDataList">树形列表数据</param>
        /// <param name="parentItem">父级model</param>
        public static void OperationChildData(List<UniWater_MenuInfo> AllList, UniWater_MenuInfo item)
        {
            if (item.children != null)
            {
                if (item.children.Count > 0)
                {
                    AllList.AddRange(item.children);
                    foreach (var subItem in item.children)
                    {
                        OperationChildData(AllList, subItem);
                    }
                }
            }
        }
View Code

 

C# 反向递归,讲树形数据结构转换为普通list

上一篇:Windows查看所有进程中所有使用某一特定dll的进程,找到并杀死进程


下一篇:c#调用热敏打印机打印小票(通用)