title: Odd behavior with the List/Dictionary .Clear() method
body: <p>I have a code block similar to this:</p>
  
  <pre><code>List&lt;Object&gt; returnObjDataLine = new List&lt;object&gt;();
  
  foreach (var tuple in dataPerTime)
  {
      returnObjDataLine.Clear();
      returnObjDataLine.Add(tuple.Item1);
      foreach (var line in PlotLines)
      {
          if (tuple.Item2.Equals(line.Key))
          {
              returnObjDataLine.Add(tuple.Item3);
          }
          else
          {
              returnObjDataLine.Add(null);
          }
      }
      returnObjData.Add(returnObjDataLine);
  }
  </code></pre>
  
  <p>However the <code>Clear()</code> method clears out the data already added to the <code>returnObjData</code> Dictionary, sort of. If there are 10,000 tuples, then after the loop runs the <code>returnObjData</code> will contain 10,000 instances of the very last data piece added (<code>Clear()</code> is not called after the last iteration).</p>
  
  <p>If I modify the code to create a new List each iteration:</p>
  
  <pre><code>foreach (var tuple in dataPerTime)
  {
      List&lt;Object&gt; returnObjDataLine = new List&lt;object&gt;();
      returnObjDataLine.Add(tuple.Item1);
      foreach (var line in PlotLines)
      {
          if (tuple.Item2.Equals(line.Key))
          {
              returnObjDataLine.Add(tuple.Item3);
          }
          else
          {
              returnObjDataLine.Add(null);
          }
      }
      returnObjData.Add(returnObjDataLine);
  }
  </code></pre>
  
  <p>the loading loop works correctly but this seems very expensive as there can be 10s if not 100s of thousands of iterations required. Creating a new object every time seems to be inefficient.</p>
  
  <p>What am I missing with <code>Clear()</code>? Is there some sort of "commit" that needs to be called first?</p>