C# – Convert IOrderedEnumerable to XElement


the following linq statement returns a IOrderedEnumerable:

        var list = from e in ritorno.Elements("dossier")
                              orderby e.Element("name")
                              select e;

How can i convert list to XElement?


list is IOrderedEnumerable<System.Xml.Linq.XElement>

Best Solution

Do you want a single XElement to contain all the elements in the sequence?

XElement element = new XElement("container", list)

(Obviously change "container" to whatever you want the containing element to be called.)

If that's not what you want, please elaborate.