开发者

Nested List Question

开发者 https://www.devze.com 2022-12-12 20:58 出处:网络
I have a question about Nested Lists. I have a class similar to the following... public class Order { private Guid id;

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 ) ...
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号