如何添加列表属性值

时间:2016-05-16 11:33:23

标签: c# winforms

我有以下代码。如何为此属性添加值?

APIKarhoBookingProperties objbooking = new APIKarhoBookingProperties();
objbooking.currency = "USD";
objbooking.price_components = ??? //how to add values this section

class APIKarhoBookingProperties
{
    public string currency { get; set; }
    public List<PriceComponent> price_components { get; set; }
}

public class PriceComponent
{
    public string component_name { get; set; }
    public double value { get; set; }
    public string description { get; set; }
    public string currency { get; set; }
}

2 个答案:

答案 0 :(得分:1)

阅读一些c#基础知识,List

price_components.Add(new PriceComponent(){ 
            component_name = "name", 
            value = 2, 
            description = "dgfdgf", 
            currency = "USD" });

答案 1 :(得分:1)

var id = context.MakeMessage().ConversationId;