开发者

can't work with XElement like with IEnumerable

开发者 https://www.devze.com 2023-03-01 12:32 出处:网络
C# var xArr = XDocument.Load(FileName) .Element(\"dataWorkers\") .Elements(\"worker\"); int i = 0; foreach (XElement item in xArr)

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

0

精彩评论

暂无评论...
验证码 换一张
取 消