给定一个父对象列表,每个对象都有一个子对象列表,我想找到与特定 ID 匹配的子对象。
public class Parent
{
public int ID { get; set; }
public List<Child> Children { get; set; }
}
public class Child
{
public int ID { get; set; }
}
现在我想要具有特定 ID 的子对象:
List<Parent> parents = GetParents();
Child childWithId17 = ???
如何使用 Linq 做到这一点?