【发布时间】:2020-03-28 06:44:47
【问题描述】:
我需要从一个复杂对象中检索所有 X 类型的对象。
public class Dog
{
public string Name {get;set;}
public int Age {get;set;}
public Owner Owner{get;set;}
public Kennel Kennel {get;set;}
}
public class Kennel
{
public string Name {get;set;}
public Address Address{get;set;}
public List<Dog> Dogs {get;set;}
}
public class Owner
{
public string Name {get;set;}
public string State {get;set;}
public Address Address{get;set;}
}
如果我有一个由 Dog 组成的对象,我需要检索所有子对象中的所有地址对象。
【问题讨论】:
-
我在你的问题中看不到任何递归。您需要 2 个对象:所有者地址和犬舍地址
-
抱歉,狗窝里应该有狗名单
-
如果狗在狗窝里,他的狗窝字段是否设置为包含它的狗窝(也就是说,这个图中有没有循环?)