我有一个从数据库中获取的匿名类型列表:
var takenChannels = (from b in bq.GetStuff(db)
where b.RecordType == "H" && b.TourStartDateTime.Date == date
select new { Start = b.TourStartDateTime, End = b.TourEndDateTime, Channel = b.RadioChannel, TourArea = b.TourArea }).ToList();
然后我使用这个列表信息在 foreach 循环中做一些事情。我想在此列表中添加一个新的匿名项目,以供我在循环中返回时使用。
就像是:
takenChannels.Union{new[] { new{Start = DateTime.Now, End = DateTime.Now.AddDays(1), Channel = 25, TourArea = "Area" }});
显然这是行不通的。我该怎么做?
编辑1:
takenChannels.Add(new { Start = s, End = e, Channel = channel, TourArea = booking.TourArea });
这是我迄今为止最接近的(感谢丹尼尔)......但我得到的错误是:
错误 6 参数 1:无法从“AnonymousType#2”转换为“AnonymousType#1”