سؤال

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.)

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top