I have these 2 classes:
class Customer
{
public string Name;
public string City;
public Order[] Orders;
}
class Order
{
public int Quantity;
public Product Product;
}
And then in the Main
I do the following:
Customer cust = new Customer
{
Name = "some name",
City = "some city",
Orders = {
new Order { Quantity = 3, Product = productObj1 },
new Order { Quantity = 4, Product = productObj2 },
new Order { Quantity = 1, Product = producctObj3 }
}
};
But I cannot initialize the array ... with a collection initializer
.
And I know that this, i.e., is possible string[] array = { "A" , "B" };
which looks the same to me...
Of course I could make separate objects of Order
, put them in an array and then assign it toOrders
, but I don't like the idea.
How can I achieve the clean and less-code-solution in this case?
Orders = new [] { }
to indicate you're initializing an array. – Unsure