0

可以说我有以下课程:

public class name()
{ 
   public string FirstName{ get; set; }
   public string LastName{ get; set; }

   public List<ItemOwner> ItemOwners { get; set; }

   public name()
   {
      this.ItemOwners = new List<ItemOwner>();
   }
} 
public class ItemOwner()
{ 
   public string nameofcat { get; set; }
   public string nameofsomething { get; set; }

   public List<AddressofCat> AddressofCats{ get; set; }

   public ItemOwner()
   {
      this.AddressofCats = new List<AddressofCat>();
   }
} 
public class AddressofCat()
{ 
   public string streetaddress{ get; set; }
   public string country { get; set; }

} 

我已调用数据库并将填充的类作为对象接收。

 var returnedcatobject = //select from database

我现在希望在列表中添加一个额外的 cataddress:

 var newcataddress = new AddressofCat();
 newcataddress.streetaddress = "Randomaddress";
 newcataddress.country = "Rhodesia";

现在完成了,我们有了一个新的 cat 地址列表,我想将它们添加到返回的 catobject 中。

我该怎么做?

4

1 回答 1

2

如果返回的catobject 是类型,List<AddressofCat>那么像这样:

 var newcataddress = new AddressofCat();
 newcataddress.streetaddress = "Randomaddress";
 newcataddress.country = "Rhodesia";

returnedcatobject.Add(newcataddress);
于 2013-10-25T10:50:56.730 回答