namespace Test { class Program { static void Main(string[] args) { var list = new List<Menu>() { new Menu () { Id = 1, Name = "主菜单1", PId = 0 }, new Menu () { Id = 2, Name = "下级菜单11", PId = 1 }, new Menu () { Id = 3, Name = "主菜单2", PId = 0 }, new Menu () { Id = 4, Name = "下级菜单21", PId = 3 }, new Menu () { Id = 5, Name = "下下级菜单212", PId = 4 } }; var dictMenus = new Dictionary<int, Menu>(list.Count); foreach (var menu in list) { dictMenus.Add(menu.Id, menu); } foreach (var value in dictMenus.Values) { if (dictMenus.ContainsKey(value.PId)) { if (dictMenus[value.PId].Children == null) dictMenus[value.PId].Children = new List<Menu>(); dictMenus[value.PId].Children.Add(value); } } var result = dictMenus.Values.Where(t => t.PId == 0).ToList(); } } public class Menu { public int Id { get; set; } public string Name { get; set; } public int PId { get; set; } public List<Menu> Children { get; set; } } }