title: Dynamically incremented property for IEnumerable collection?
body: <p>I have a collection that gets arbitrarily sorted based on conditions. My class has an "Ordinal" int property that I would like dynamically populated after the collection gets ordered. Here is what I have so far:</p>
  
  <pre><code>var result = new List&lt;MyClass&gt;();
  foreach (var x in items)
  {
    x.TestA = x.TestA;
    x.TestB = x.TestB;
    x.TestC = x.TestC;
  }
  ...
  var ordered = result.AsEnumerable();
  if (...) ordered.OrderBy(x =&gt; x.TestA);
  else if (...) ordered.OrderBy(x =&gt; x.TestB);
  else if (...) ordered.OrderBy(x =&gt; x.TestC);
  ...
  return ordered.ToList()
  </code></pre>
  
  <p>Before returning the ordered list, what is the best way to populate the "Ordinal" property of the "MyClass" objects in the collection with its index location? I am reluctant to create another loop at the end since I have thousands of records. Is this the only way? Thanks for any help or advise.</p>