简单的递归加载树形菜单
由于之前只做个2级的菜单加载的编写,前段时间一直在考虑怎么用递归来完成无限级加载,(一直对递归有点陌生,之前很少用的缘故),今天通过了解递归和自己的摸索,基本算是完成了,其实代码很简单,希望各位大牛勿拍砖啊, public static void MenuLoad() { var data = _list.Where(t => t.ParentId == 0); foreach (var tree in data) { Console.WriteLine(tree.Name); AddChildNode(tree.Id); } } public static void AddChildNode(int id) { var data = _list.Where(t => t.ParentId == id); foreach (var tree in data) { Console.WriteLine(tree.Name); AddChildNode(tree.Id); } } 来源: https://www.cnblogs.com/guobingbing/p/3735868.html