Closed. This question does not meet Stack Overflow guidelines。它当前不接受答案。
想改善这个问题吗?更新问题,以使为on-topic。
6年前关闭。
Improve this question
在下面的代码中,我已经解释了我想要的内容,请有人帮助我解决此问题。
如果只需要获取
想改善这个问题吗?更新问题,以使为on-topic。
6年前关闭。
Improve this question
在下面的代码中,我已经解释了我想要的内容,请有人帮助我解决此问题。
public class Person
{
public IEnumerable<Child> Children { get; set; }
}
public class Child
{
public IEnumerable<GrandChild> GrandChildren { get; set; }
}
public class SearchingClass
{
public void Search()
{
IEnumerable<Person> persons = MyPersons;
IEnumerable<GrandChild> grandChildren = MyGrandChildren
//Now I want only the Grand Children who are grand children of persons in Persons List
//How can I write a query for this ?
}
}
最佳答案
perons.SelectMany(p => p.Children)
.SelectMany(c => c.GrandChildren);
// add Distinct() if you need distinct results
如果只需要获取
grandChildren
集合中的大子代,则:grandChildren.Intersect(
perons.SelectMany(p => p.Children)
.SelectMany(c => c.GrandChildren));
关于c# - 如何从人员列表中查询大 child ? ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20189088/
10-16 20:00