I have a question about Nested Lists.
I have a class similar to the following...
public class Order
{
private Guid id;
[DataMember]
public Guid ID { get { return id; } set { id = value; }}
private List<Items> orderItems;
[DataMember]
public List<Items> OrderItems { get { return orderItems; } set { orderItems= value; } }
}
public class Items
{
private string itemName;
[DataMember]
public string ItemName { get { return itemName; } set { itemName = value; }}
}
This seems to be ok until i reference the list within in my code saying something similar to
if myItemName = this.order.orderItems[0].itemName
The problem come开发者_StackOverflow社区s when I add the "[0].itemName". Can anyone help me with what I am missing?
You appear to be trying to access the private field rather than the public property. Try: (note the case change)
myItemName = this.order.OrderItems[0].ItemName
Also, the syntax looks weird, what language are you using? Did you mean:
if ( this.order.OrderItems.Count > 0 && myItemName == this.order.OrderItems[0].ItemName ) ...
精彩评论