title: How to implement ICollection<T> on an IEnumerable<T>
body: <p>I would like to know how to program what Microsoft is suggesting from the MSDN <a href="http://msdn.microsoft.com/en-us/library/dn169389(v=vs.110).aspx" rel="nofollow">guidelines for collections</a>, which state the following:</p>
  
  <pre><code>AVOID using ICollection&lt;T&gt; or ICollection as a parameter just to access the
  Count property. Instead, consider using IEnumerable&lt;T&gt; or IEnumerable and
  dynamically checking whether the object implements ICollection&lt;T&gt; or ICollection.
  </code></pre>
  
  <p>In short, how do I implement ICollection on an IEnumerable?  Microsoft has links all over that article, but no "And here is how you do this" link.</p>
  
  <p>Here is my scenario. I have an MVC web app with a grid that will paginate and have sorting capability on some of the collections.  For instance, on an Employee administration screen I display a list of employees in a grid.</p>
  
  <p>Initially I returned the collection as IEnumerable.  That was convenient when I didn't need to paginate.  But now I'm faced with paginating and needing to extract the Count of employee records to do that.  One <em>workaround</em> was to pass an employeeCount integer by ref to my getEmployeeRecords() method and assign the value within that method, but that's just messy.</p>
  
  <p>Based on what I've seen here on StackOverflow, the general recommendation is to use IEnumerable instead of ICollection, or Collection, or IList, or List.  So I'm not trying to open up a conversation about that topic. <strong>All I want to know is how to make an IEnumerable implement an ICollection, and extract the record count,</strong> so my code is more aligned with Microsoft's recommendation. A code sample or clear article demonstrating this would be helpful.</p>
  
  <p>Thanks for your help!</p>