Đệ quy get all by parentid

private async Task<List<AppNav>> GetAllNavsByParentId(List<AppNav> navs, long? parentId)

        {

            List<AppNav> viewNavs = new List<AppNav>();

            for (var i = 0; i < navs.Count; i++)

            {

                if (navs[i].ParentId == parentId)

                {

                    viewNavs.Add(navs[i]);

                    var items = await GetAllNavsByParentId(navs, navs[i].Id);

                    for(int j=0;j<items.Count;j++)

                    {

                        viewNavs.Add(items[j]);

                    }

                }

            }

            return viewNavs;

        }

428

0 Phản hồi Viết phản hồi