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
.)
精彩评论