返回最大深度
Console.WriteLine(GetMaxDepth(list)); public static int GetMaxDepth(List<Department> list, int? id = null) { if (list == null) throw new Exception("未将对象引用设置到对象的实例。"); var depaList = list.Where(x => x.FParentID == id).ToList(); if (depaList.Count == 0) return 0; int max = 0; foreach (var item in depaList) { if (GetMaxDepth(list, item.FID) > max) { max = GetMaxDepth(list, item.FID); } } return ++max; //Func<Guid, int> fun = null; //fun = new Func<Guid, int>(x => //{ // return 1; //}); //fun = delegate(Guid s) //{ //}; }