C# 无法将类型System.Collections.Generic.IEnumerable隐式转换为System.Collections.Generic.List
我只需要为每个订单获得一条记录,但如果有广告,我也需要记录。但是当我使用Concat时,我得到了这个错误 无法将类型C# 无法将类型System.Collections.Generic.IEnumerable隐式转换为System.Collections.Generic.List,c#,linq,C#,Linq,我只需要为每个订单获得一条记录,但如果有广告,我也需要记录。但是当我使用Concat时,我得到了这个错误 无法将类型System.Collections.Generic.IEnumerable隐式转换为System.Collections.Generic.List。存在显式转换(是否缺少强制转换?) 这里的问题是: pom = pom.Concat(advirtise); ^ ^-------+------------^ | | | +--
System.Collections.Generic.IEnumerable
隐式转换为System.Collections.Generic.List
。存在显式转换(是否缺少强制转换?)
这里的问题是:
pom = pom.Concat(advirtise);
^ ^-------+------------^
| |
| +-----> returns IEnumerable<Something> -----+
| |
+----- which you try to store into List<Something> <-----+
下面是一个演示问题的简短程序:
var pom = new[] { "a", "b", "c" }.ToList();
pom = pom.Concat(new[] { "x", "y", "z" }); // CS0266 - cannot implicitly ...
下面是应该如何写的:
var pom = new[] { "a", "b", "c" }.ToList();
pom = pom.Concat(new[] { "x", "y", "z" }).ToList();
pom = pom.Concat(advirtise).ToList();
var pom = new[] { "a", "b", "c" }.ToList();
pom = pom.Concat(new[] { "x", "y", "z" }); // CS0266 - cannot implicitly ...
var pom = new[] { "a", "b", "c" }.ToList();
pom = pom.Concat(new[] { "x", "y", "z" }).ToList();