title: How do I get the index of items in a group
body: <p>The code below gives me an Argument Out Of Range Exception. I am trying to get certain items of the current index with the ElementAt() exension method.  What am I missing here:</p>
  
  <pre><code>var orders = cart.GroupBy(x =&gt; x.ClientForOrdersId).Select
              ((x, i) =&gt;
               new Client_InvoiceBalance()
                   {
                       IsMainClient = x.Key == x.ElementAt(i).MainClientId ? true : false,
                       MainClientId = x.ElementAt(i).MainClientId,
                       OtherClientId = x.ElementAt(i).ClientForOrdersId,
                       InvoiceOrderNumber = orderNumber,
                       IsPaidInFull = false
                   }).ToList();
  </code></pre>