初始化类的数组属性

时间:2019-09-16 19:00:53

标签: arrays object initialization

如何初始化一个类中某个属性的数组,而该属性是另一个类。

 UserResponse res = new UserResponse()
           {
            //array has to be initialized in this block
             Products = new Inventory[2] { }

           };

  public class UserResponse
  {
    public UserResponse();

    public Inventory[] Products { get; set; }
  }

   public class Inventory
  {
    public Inventory();

    public string Type { get; set; }
    public string Status { get; set; }
  }

如何在同一块中初始化大小为2的数组。

0 个答案:

没有答案