title: Add an Index to a list that resets depending on Id group
body: <p>Given an object such as: </p>
  
  <pre><code>public class Test
  {
     public int Id { get; set;}
     public int Field1 { get; set; }
     public int Field2 { get; set; }
  }
  </code></pre>
  
  <p>Which is populated like this:</p>
  
  <pre><code>List&lt;Test&gt; list = new List&lt;Test&gt;();
  list.Add( new Test { Id = 1, field1 = 1});
  list.Add( new Test { Id = 1, field1 = 2});
  list.Add( new Test { Id = 2, field1 = 3});
  list.Add( new Test { Id = 2, field1 = 4});
  </code></pre>
  
  <p>I can create an index column and iterate through the list:</p>
  
  <pre><code>var indexList = list.Select((t, i) =&gt; new {t, index = i}).ToList();
  
  foreach (var t in indexList)
  {
      Console.WriteLine("ID: " + t.t.Id + " ---- Index:" + t.index);
  }
  </code></pre>
  
  <p>And I get results like this:</p>
  
  <pre><code>ID: 1 ---- Index:0
  ID: 1 ---- Index:1
  ID: 2 ---- Index:2
  ID: 2 ---- Index:3
  </code></pre>
  
  <p>What I really want to do is reset the index for each Id group so that I get output like this:</p>
  
  <pre><code>ID: 1 ---- Index:0
  ID: 1 ---- Index:1
  ID: 2 ---- Index:0
  ID: 2 ---- Index:1
  </code></pre>
  
  <p>I've tried playing with GroupBy without much luck.</p>
  
  <p>Can someone point me in the right direction please?</p>
  
  <p>Thanks</p>