I have the following classes…
public class Order
{
private Guid id;
public Guid ID
{
get { return id; }
set { id = value; }
}
private List<Items> orderItems;
public List<Items> OrderItems
{
get { return orderItems; }
set { orderItems= value; }
}
}
public class Item
{
private Guid id;
public Guid ID
{
get { return id; }
set { id = value; }
}
private string itemName;
public string ItemName
{
get { return itemName; }
set { itemName = value; }
}
}
Then within my application I try the following….
ACME.Order newOrder = new ACME.Order();
newOrder.ID = xxx
newOrder.OrderItems = new List<OrderItem> {
new ACME.OrderItem {
ID = xxx
ItemName = xxx
}
}
However I get the error “Cannot implicitly convert type 'System.Collections.Generic.List<ACME.Item>' to ACME.Item[]. The strange thing as well is that all I don’t have an “Add” option on any of my list objects.
Is your application on the client side of a Web service?
If so, the proxy generator for .asmx and WCF Web services generates an array
T[]on the client side where a service interface uses aList<T>(or, indeed, any other enumerated type).Your application will need to cast the list to an array (use
.ToArray()) to set the array property client-side.