'Cannot implicitly convert type 'System.Collections.Generic.List<string>' to 'System.Collections.Generic.List<System.Xml.Linq.XElement>'

I have the code below:
List<XElement> DBListSetxElements = DbListSetItems[0].Value.Root.Descendants("ListSet").Select(desc => desc.Attribute("Name")).Distinct().ToList();

While compile getting error Error CS0029 Cannot implicitly convert type 'System.Collections.Generic.List<string>' to 'System.Collections.Generic.List<System.Xml.Linq.XElement>'

Need Help.



Solution 1:[1]

Actually you need to provide the DbListSetItems class definition if you want any more help. Seems you're trying to select the name of the XML element and perhaps in the DbListSetItems data you have the content.

This solution creates a XML Element but the content is null As I said if you want to populate with some other DbListSetItems property you need to provide us some info (or get the apropiate value from it like desc.Attribute("theApropiateAtributeNameValue") ) instead null:

        List<XElement> DBListSetxElements = DbListSetItems[0].Value.Root.Descendants("ListSet")
            .Select(desc => new XElement(desc.Attribute("Name"), null)).Distinct().ToList();

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 J.Salas