简体   繁体   English

将匿名对象添加到匿名列表

[英]Add an anonymous object to an anonymous list

I have a list of anonymous types stored in b (which comes from a list) and i want to add a new object to the list. 我有一个存储在b中的匿名类型列表(来自列表),我想在列表中添加一个新对象。 When i try to add a new anonymous object to this list i get this error: 当我尝试将新的匿名对象添加到此列表时,我收到此错误:

The best overloaded method match for 'System.Collections.Generic.List.Add(AnonymousType#1)' has some invalid arguments. 'System.Collections.Generic.List.Add(AnonymousType#1)'的最佳重载方法匹配具有一些无效参数。 And i also get this error: Argument 1: cannot convert from 'AnonymousType#2' to 'AnonymousType#1' 我也得到这个错误:参数1:无法从'AnonymousType#2'转换为'AnonymousType#1'

 var b = user.Orders.Select(i => new { id = i.BillingId , text = i.Billing.ToString() }).ToList();
 b.Add(new { id = 0 , text = "New Billing Address" });

Thanks in advance 提前致谢

What type is BillingId ? BillingId是什么类型的? You may need a suffix on the digit literal, or a cast, or get the Value if it is nullable.. 您可能需要数字文字的后缀或转换,或者如果它可以为空,则获取Value

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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