开发者

Guidance with a translation in Linq to Xml

开发者 https://www.devze.com 2022-12-12 20:01 出处:网络
Can someone help with an explanation of what does this mean: ... .Select(Func<XElement, XElement>selector)

Can someone help with an explanation of what does this mean:

... .Select(Func<XElement, XElement>selector)

Please an example of what should go i开发者_StackOverflow中文版n as parameter will be appreciated.

Also found it a little bit difficult naming this question. Suggestion will also be appreciated.


It's a function taking XElement as argument and returning an XElement, so for instance:

public XElement someFunction(XElement argument)
{
    XElement someNewElement = new XElement();
    ... // do something with someNewElement, taking into account argument
    return someNewElement;
}

Func<XElement, XElement> variableForFunction = someFunction;

.... .Select(variableForFunction);

I'm not interely sure if you have to assign it to a variable first, you could probably just do this:

... .Select(variableForFunction);

give it a try (and let me know if it works :) )

oh and for more information, here's the msdn article, it also explains how to use delegates:

Func<XElement, XElement> variableForFunction = delegate(XElement argument)
    {
        ....//create a new XElement
        return newXElement;
    }

and how to use lambdas, for instance:

Func<XElement, XElement> variableForFunction = s => {
    ....;//create an XElement to return
    return newXElement;
}

or, in this instance, use the lambda directly:

.... .Select( s => {
    ....;//create an XElement to return
    return newXElement;
})

edited it following Pavel's comment

0

精彩评论

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