如何从以下示例中获取结果集。
public class Parent
{
public string Id { get; set; }
public List<Child> Children { get; set; }
}
public class Child : Parent
{
public bool Isleaf { get; set; }
}
Child c1 = new Child();
c1.Id = "c1";
c1.Isleaf = false;
Child c2 = new Child();
c2.Id = "c2";
c2.Isleaf = true;
Child c11 = new Child();
c11.Id = "c11";
c11.Isleaf = true;
Child c12 = new Child();
c12.Id = "c12";
c12.Isleaf = false;
Child c121 = new Child();
c121.Id = "c121";
c121.Isleaf = true;
c12.Children = new List<Child>() { c121 };
c1.Children = new List<Child>() { c11, c12 };
Parent p = new Parent();
p.Id = "P1";
p.Children = new List<Child>() { c1, c2 };
从上面的集合中,我想获取所有叶子节点为 true 的子节点的列表,即 List leafNode=new List {c2,c11,c21};