c# Linq List 添加条目
本文关键字:添加 List Linq | 更新日期: 2023-09-27 18:33:18
我有这个 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();
我想向列表中添加第二个定价对象 {成人 = 1,价格 = x.rate }
我怎样才能做到这一点?
添加一个逗号和另一个定价对象:
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();