title: C# XML LINQ Query to LIST<>
body: <p>I'm trying to turn an XML document into a List&lt;> with a predefined Class</p>
  
  <p>My xml dataset TestData.xml</p>
  
  <pre><code>&lt;Objects&gt;
      &lt;Object ID="1"&gt;
          &lt;ItemOne&gt;"Hickory"&lt;/ItemOne&gt;
          &lt;ItemTwo&gt;"Dickory"&lt;/ItemTwo&gt;
          &lt;ItemThree&gt;"Dock"&lt;/ItemThree&gt;
      &lt;/Object&gt;
  
      &lt;Object ID="2"&gt;
          &lt;ItemOne&gt;"The"&lt;/ItemOne&gt;
          &lt;ItemTwo&gt;"Mouse"&lt;/ItemTwo&gt;
          &lt;ItemThree&gt;"Went"&lt;/ItemThree&gt;
      &lt;/Object&gt;
  &lt;/Objects&gt;
  </code></pre>
  
  <p>The Main program</p>
  
  <pre><code>class Program
  {
      static void Main(string[] args)
      {
  
          XElement TestData = XElement.Load("TestData.xml");
  
         List&lt;Test&gt; myTest = new List&lt;Test&gt;(from d in TestData.Descendants("Objects")
                                       select new Test(
                                           d.Element("ItemOne").Value.ToString(),
                                           d.Element("ItemTwo").Value.ToString(),
                                           d.Element("ItemThree").Value.ToString()));
  
          myTest.ForEach(i =&gt; Console.WriteLine("{0} {1} {2}", i.itemOne, i.itemTwo, i.itemThree));
  
          Console.ReadLine();
      }
  
  
  }
  </code></pre>
  
  <p>The class I'm trying to form the data to</p>
  
  <pre><code>class Test
  {
      public string itemOne { get; set; }
      public string itemTwo { get; set; }
      public string itemThree { get; set; }
  }
  </code></pre>
  
  <p>I would like to get out</p>
  
  <pre><code>Hickory Dickory Dock
  The Mouse went
  </code></pre>
  
  <p>but I end up getting nothing.  It looks like the LINQ Query finds the data but never assigns it to the <code>List&lt;Test&gt;</code> myTest, the value shows as null in the debugger.  I'm not sure what I'm doing wrong.</p>
  
  <p>I want to convert the XML to <code>List&lt;Test&gt;</code> so I can randomly rearrange through the objects.  I was going to just use int[] array and sort by "ID" but I don't know the actual length of the array and want to assign it on the fly so I am forced to do a <code>list&lt;&gt;</code>.  I am open to other suggestions of accomplishing this.</p>