【发布时间】:2014-05-03 21:40:10
【问题描述】:
我收到以下错误
Cannot implicitly convert type
'System.Collections.Generic.List<AnonymousType#1>' to
'System.Collections.Generic.List<string>'
我尝试阅读有关堆栈溢出的类似问题,但没有找到解决方案。 我的代码如下
var head =
from key in doc.Descendants("Header").Descendants("Article")
select new
{
value = (key.Value == String.Empty ?
from q in doc.Descendants("Header").Descendants("Article") select q.Value : from a in doc.Descendants("Header").Descendants("Article")
select a.Attribute("DefaultValue").Value)
};
List<string> hsourceFields = head.ToList();
如果 xml 节点的值为空,我正在读取为该 xml 节点指定的默认值
<Header>
<Article>News</Article>
<Article DefaultValue ="Sport"></Article>
</Header>
我希望能够通过收到错误返回一个我无法返回的列表。
【问题讨论】:
-
如果将 List
更改为 List 会怎样
标签: c# linq linq-to-xml