tags:

views:

55

answers:

1

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 comes when I add the "[0].itemName". Can anyone help me with what I am missing?

+1  A: 

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 ) ...
John Weldon
that was my first reaction, he accesses the private field of the item class.
Sem Dendoncker
yes that was it. sorry late night, not sure how the private item was even showing up in InteliSense.Thanks.
Kuruption
Thanks, you can mark this answer as accepted if this resolved your issue :)
John Weldon