title: C# LINQ to Objects: Group By/Sum help
body: <p>In a list of transaction objects, I am attempting to group by BatchNo then sum the Amounts.</p>
  
  <pre><code>public class Extract
  {
      // Notable fields in TRANSACTION are: String mBatchNo, String mAmount
      private List&lt;Transaction&gt; Transactions;
  
      public void testTransactions()
      {
  
          // Sum of amounts grouped by batch number
          var sGroup = from t in Transactions
                       group t by t.mBatchNo into g
                       select new { batchNo = g.Key, 
                                    totalAmount = g.Max(a =&gt; (Int32.Parse(a.mAmount)))};
      }
  }
  </code></pre>
  
  <p>At this point, I step into the code look through the locals window to see what my result set is to check against the file I've imported to this object.</p>
  
  <p>The last batch in the file has 3 records, 100 amount each which can be seen drilling into the Transactions list object.  However drilling down into the sGroup result finds the same batch to have 100 amount total (Should be 300).  What have I messed up in this query?</p>
  
  <p>Note that I've stored this as a string since we're zero filled to the left of a 8 character field.  For export reasons I decided to store as a string.  Though this can (and probably will) be changed it does not answer my question: How to make this query aggregate the sum into sets by BatchNo?</p>