list获取所有上级

/// <summary>
/// 获取所有上级
/// </summary>
/// <param name="list"></param>
/// <param name="ID"></param>
/// <returns></returns>
public static IEnumerable<HelpDocumentType> GetFatherList(IList<HelpDocumentType> list, int ID)
{
var query = list.Where(p => p.ID == ID).ToList();
return query.ToList().Concat(query.ToList().SelectMany(t => GetFatherList(list, t.ParentID)));
}

上一篇:C#


下一篇:Linq之ToList