title: Sum Dictionary value by Key
body: <p>I have an XML document i am parsing using XDocument:</p>
  
  <pre><code>XDocument _document = XDocument.Parse(XMLString);
  </code></pre>
  
  <p>The XML i'm reading in (real example could contain many of same ItemNumber):</p>
  
  <pre><code>&lt;Line&gt;
   &lt;ITEMNMBR&gt;18-4695&lt;/ITEMNMBR&gt;
   &lt;UNITCOST&gt;2.00000&lt;/UNITCOST&gt;
   &lt;UNITPRCE&gt;7.00000&lt;/UNITPRCE&gt;
   &lt;QUANTITY&gt;15.00000&lt;/QUANTITY&gt;
  &lt;/Line&gt;
  &lt;Line&gt;
   &lt;ITEMNMBR&gt;18-4695&lt;/ITEMNMBR&gt;
   &lt;UNITCOST&gt;3.00000&lt;/UNITCOST&gt;
   &lt;UNITPRCE&gt;7.00000&lt;/UNITPRCE&gt;
   &lt;QUANTITY&gt;22.00000&lt;/QUANTITY&gt;
  &lt;/Line&gt;
  </code></pre>
  
  <p>I then read this xml into a Dictionary :</p>
  
  <pre><code>var lines = _document.Descendants("Line")
                    .Select(l =&gt; l.Elements().ToDictionary(e =&gt; e.Name.LocalName, e =&gt; e.Value)).ToList();
  </code></pre>
  
  <p>Next, Get a list of distinct ItemNumbers:</p>
  
  <pre><code> var itemNumbers = lines.Where(dict =&gt; dict.ContainsKey("ITEMNMBR"))
                      .Select(dict =&gt; dict["ITEMNMBR"])
                      .Distinct()
                      .ToList();
  </code></pre>
  
  <p>Now that i have a list of distinct ItemNumbers, i need to get totals for each, so i loop the Dictionary:</p>
  
  <pre><code>foreach (string itemNumber in itemNumbers)
    {...
  </code></pre>
  
  <p>Inside the loop is where i query for the values by ItemNumber:</p>
  
  <pre><code>var qty = lines.Where(dict =&gt; dict.ContainsValue(itemNumber))
                      .Select(dict =&gt; dict["QUANTITY"])
                      .ToList();
  </code></pre>
  
  <p>The next area is where i'm having an issue. Can i calculate the sum for qty? I tried something like this, but get compiler errors (which is understandable, i'm trying to sum a string)</p>
  
  <pre><code>int sum = qty.Sum(x =&gt; Convert.ToDecimal(x.Value));
  </code></pre>
  
  <p>I get "String does not contain a definition for Value"...</p>
  
  <p>How can i sum these results?</p>