title: Merge the rows of a list into a single row
body: <p>I have a payment class similar to the following</p>
  
  <pre><code>class Payment
  {
      public int ContactId {get; set;}
      public DateTime Date {get; set;}
      public decimal Amount {get; set;}
  }
  </code></pre>
  
  <p>In a payment list, I would like to sum the <strong>Amount</strong> field for the rows that have the same value in the <strong>ContactId</strong> field and then in the <strong>Data</strong> field.</p>
  
  <p>Here is an example:</p>
  
  <pre><code>List&lt;Payment&gt; payments;
  Payment payment;
  payment = new Payment
  {
      ContactId = 1,
      Date = DateTime.Parse("01/01/2018"),
      Amount = 1m
  }
  payments.Add(payment);
  
  payment = new Payment
  {
      ContactId = 1,
      Date = DateTime.Parse("01/01/2018"),
      Amount = 1m
  }
  payments.Add(payment);
  
  payment = new Payment
  {
      ContactId = 2,
      Date = DateTime.Parse("01/01/2018"),
      Amount = 1m
  }
  payments.Add(payment);
  </code></pre>
  
  <p>So I have a list of three elements.</p>
  
  <p>I look for a solution that in this case gives me back a list consisting of two rows.</p>
  
  <p>Row 1: ContactId=1; Date="01/01/2018"; Amount=2;</p>
  
  <p>Row 2: ContactId=2; Date="01/01/2018"; Amount=1;</p>