C#递归获取LINQ列表中所有子级项目
C# 全选
public static class tb_MyGroup_Recursive
{
/// <summary>
/// 递归获取组织架构所有子级
/// </summary>
/// <param name="items">所有组织架构</param>
/// <param name="parentCode">父级编码</param>
/// <returns></returns>
public static IEnumerable<tb_MyGroup> Recursive(this IEnumerable<tb_MyGroup> items, string parentCode)
{
List<tb_MyGroup> inner = new List<tb_MyGroup>();
foreach (var t in items.Where(item => item.ParentGroupCode == parentCode))
{
inner.Add(t);
inner = inner.Union(Recursive(items, t.GroupCode)).ToList();
}
return inner;
}
}
版权声明:本文为开发框架文库发布内容,转载请附上原文出处连接
NewDoc C/S框架网