How Can I Get a List<int> From Linq to XML that Produces List<List<int>>?

Posted by DaveDev on Stack Overflow See other posts from Stack Overflow or by DaveDev
Published on 2010-04-28T21:57:46Z Indexed on 2010/04/28 22:07 UTC
Read the original article Hit count: 155

Filed under:
|
|

I have an XML snippet as follows:

<PerformancePanel>
  <LegalText>
    <Line id="300" />
    <Line id="304" />
    <Line id="278" />
  </LegalText>
</PerformancePanel>

I'm using the following code to get an object:

    var performancePanels = new
    {
        Panels = (from panel in doc.Elements("PerformancePanel")
                select new
                {
                    LegalTextIds = (from legalText in panel.Elements("LegalText").Elements("Line")
                                 select new List<int>()
                                 {
                                     (int)legalText.Attribute("id")
                                 }).ToList()
                }).ToList()
    };

The type of LegalTextIds is List<List<int>>. How can I get this as a List<int>?

© Stack Overflow or respective owner

Related posts about c#

Related posts about LINQ