title: Iterating through list and creating summary lines on the fly
body: <p><strong>EDIT: I missed a crucial point: .NET 2.0</strong></p>
  
  <p>Consider the case where I have a list of unsorted items, for the sake of simplicity of a type like this:</p>
  
  <pre><code>class TestClass
  {
      DateTime SomeTime;
      decimal SomePrice;
  
      // constructor
  }
  </code></pre>
  
  <p>I need to create a report-like output, where the total prices for each day are accumulated. There should be one line for each item, folled by the appropriate summary lines.</p>
  
  <p>Take this test data:</p>
  
  <pre><code>List&lt;TestClass&gt; testList = new List&lt;TestClass&gt; { 
  new TestClass(new DateTime(2008,01,01), 12),
  new TestClass(new DateTime(2007,01,01), 20),
  new TestClass(new DateTime(2008,01,01), 18)
  };
  </code></pre>
  
  <p>The desired output would be something like this:</p>
  
  <pre><code>2007-01-01: 
  20
  Total: 20
  
  2008-01-01: 
  12
  18
  Total: 30
  </code></pre>
  
  <p>What's the best way to approach such scenarios? In the case of such a list, I would implement the IComparable interface for TestClass, so that the list can be sorted.</p>
  
  <p>To create the report itself, something like this could be used (let's assume that we have methods for tasks like accumulating the prices, keeping track of the current date etc):</p>
  
  <pre><code>for (int i=0;i&lt;testList.Count;i++)
  {
      if (IsNewDate(testList[i]))
      {
          CreateSummaryLine();
          ResetValuesForNewDate();
      }
  
      AddValues(testList[i]);
  }
  
  // a final summary line is needed to include the data for the last couple of items.
  CreateSummaryLine();
  </code></pre>
  
  <p>This works alright, but I have a strange feeling as far as the second "CreateSummaryLines" is concerned.</p>
  
  <p>In what ways do you handle such situations (especially considering the fact, the we need to work with a List&lt;> of items rather than a pre-categorized Dictionary or something like that)?</p>