c#Linq List添加条目

时间:2016-02-05 11:28:02

标签: c# linq

我有这个C#LINQ

List<RateRecord> ls = occupancyList.Where(s => s.publish_flag.Contains("0020")).Select(x => new RateRecord()
        {
            RATECODE = x.rate_code.Trim(),
            Occ = new List<RateRecordDtl>() 
            { 
                new RateRecordDtl { date = dateFromShort, pricing = new List<Pricing>() {new Pricing {adults = 2, price = x.rate }} 
            }
        }
        ).ToList();

我想在List中添加第二个定价对象 {adults = 1,price = x.rate}

我怎样才能做到这一点?

1 个答案:

答案 0 :(得分:1)

添加逗号和另一个Pricing对象:

List<RateRecord> ls = occupancyList.Where(s => s.publish_flag.Contains("0020")).Select(x => new RateRecord()
        {
            RATECODE = x.rate_code.Trim(),
            Occ = new List<RateRecordDtl>() 
            { 
                new RateRecordDtl { date = dateFromShort, pricing = new List<Pricing>() {
                    new Pricing {adults = 2, price = x.rate },
                    new Pricing {adults = 1, price = x.rate }} 
            }
        }
        ).ToList();