title: Converting XML To dictionary
body: <p>I am converting this XML:</p>
  
  <pre><code>&lt;root&gt;
      &lt;item id="1" level="1" /&gt;
      &lt;item id="2" level="1"&gt;
          &lt;item id="3" level="2" /&gt;
          &lt;item id="4" level="2" &gt;
              &lt;item id="5" level="3"&gt;
                  &lt;item id="6" level="4" /&gt;
              &lt;/item&gt;
          &lt;/item&gt;
          &lt;item id="7" level=2" /&gt;
      &lt;/item&gt;
  &lt;/root&gt;
  </code></pre>
  
  <p>into a dictionary using this:</p>
  
  <pre><code>XElement root = XElement.Parse(strSerializedoutput);
  Dictionary&lt;int, Pair&gt; list = root.Descendants("item").ToDictionary(x =&gt; (int)x.Attribute("id"), x =&gt;
  {
      var pId = x.Parent.Attribute("id");
      var depthLevel = x.Attribute("level");
      if (pId == null)
      {
          return new { parentID = 0, level = (int)depthLevel };
      }
      else
      {
          return new { parentID = (int)pId, level = (int)depthLevel };
      }
  });
  </code></pre>
  
  <p>where pair is:</p>
  
  <pre><code>    public class Pair
      {
          int parentID;
          int level;
      }
  </code></pre>
  
  <p>Output I want to be:</p>
  
  <pre><code>ID | ParentID  | level
  ------------------------
  1     NULL         1
  2     NULL         1
  3      2           2
  4      2           2
  5      4           3
  6      5           4
  7      2           2
  </code></pre>
  
  <p>but i am getting an error saying </p>
  
  <p>Error   35  Cannot implicitly convert type
   'System.Collections.Generic.Dictionary int,AnonymousType#1' to 'System.Collections.Generic.Dictionary int,ProposalSystem.handlers.main.Pair'</p>