简体   繁体   中英

c# Linq List add entry

I have this 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();

I want to add to the List a second Pricing object {adults = 1, price = x.rate }

How can I achieve that?

Add a comma and another Pricing object:

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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM