can't work with XElement like with IEnumerable
-
26-10-2019 - |
문제
C#
var xArr = XDocument.Load(FileName)
.Element("dataWorkers")
.Elements("worker");
int i = 0;
foreach (XElement item in xArr)
F#
let xArr = (((XDocument.Load fileName).Element <| XName.Get "Dict").Element <| XName.Get "dictNode")
for x in xArr do
()
Error
The type 'XElement' is not a type whose values can be enumerated with this syntax, i.e. is not compatible with either seq<_>, IEnumerable<_> or IEnumerable and does not have a GetEnumerator method
why ? I can't find my mistake.
해결책
The Element Method returns an XElement (which is not enumerable).
The Elements Method returns an IEnumerable<XElement>.
다른 팁
In the F# code you're using Element
which finds a single element rather than Elements
which finds a sequence of elements.
(The C# code should be fine - there you're already using Elements
.)
제휴하지 않습니다 StackOverflow