我已经用C#编写了一个LINQ查询
string etXML = File.ReadAllText("ET_Volume.xml");
string[] allLinesInAFile = etXML.Split('\n');
var possibleElements = from line in allLinesInAFile
where !this.IsNode(line)
select new { Node = line.Trim() };
string[] xmlLines = possibleElements.ToArray<string>();
问题出现在最后一行,出现了以下错误:
System.Collections.Generic.IEnumerable<AnonymousType#1>
不包含定义为ToArray
的内容,而最佳扩展方法重载System.Linq.Enumerable.ToArray<TSource>(System.Collections.Generic.IEnumerable<TSource>)
有一些无效的参数。- 实例参数: 无法将
System.Collections.Generic.IEnumerable<AnonymousType#1>
转换为System.Collections.Generic.IEnumerable<string>
var
转换为string[]
?
var
进行转换”,因为var
不是一种类型。var
是一个关键字,告诉编译器从右侧的表达式推断静态类型。(您可能已经知道这一点,但我想指出您所提问的措辞不准确。) - stakx - no longer contributing