title: C# - using Linq to XML to populate list of objects
body: <p>I'm trying to use the contents of an XML file as the data source to a List of objects. The object looks like this:</p>
  
  <pre><code>public class QuestionData
  {
  public string QuestionName{get;set;}
  public List&lt;string&gt; Answers{get;set;}
  }
  </code></pre>
  
  <p>And here is my XML:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;QuestionData&gt;
      &lt;Question&gt;
          &lt;QuestionName&gt;Question 1&lt;/QuestionName&gt;
          &lt;Answers&gt;
              &lt;string&gt;Answer 1&lt;/string&gt;
              &lt;string&gt;Answer 2&lt;/string&gt;
              &lt;string&gt;Answer 3&lt;/string&gt;
              &lt;string&gt;Answer 4&lt;/string&gt;
          &lt;/Answers&gt;
      &lt;/Question&gt;
      &lt;Question&gt;
          &lt;QuestionName&gt;Question 2&lt;/QuestionName&gt;
          &lt;Answers&gt;
              &lt;string&gt;Answer 1&lt;/string&gt;
              &lt;string&gt;Answer 2&lt;/string&gt;
              &lt;string&gt;Answer 3&lt;/string&gt;
          &lt;/Answers&gt;
      &lt;/Question&gt;
  &lt;/QuestionData&gt;
  </code></pre>
  
  <p>The code I'm using to try and do this is:</p>
  
  <pre><code>var xml = XDocument.Load ("C:\temp\xmlfile.xml");
  
  List&lt;QuestionData&gt; questionData = xml.Root.Elements("Question").Select 
  (q =&gt; new QuestionData {
    QuestionName = q.Element ("QuestionName").Value, 
    Answers = new List&lt;string&gt; { 
      q.Element ("Answers").Value }
  }).ToList ();
  </code></pre>
  
  <p>The code compiles, but I'm not getting any data from the XML. I looped through questionData to try and display the information to the console but it was empty.</p>