title: How should I get the length of an IEnumerable?
body: <p>I was writing some code, and went to get the length of an IEnumerable.  When I wrote <code>myEnumerable.Count()</code>, to my surprise, it did not compile.  After reading <a href="https://stackoverflow.com/questions/2521592/difference-between-ienumerable-count-and-length">Difference between IEnumerable Count() and Length</a>, I realized that it was actually Linq that was giving me the extension method.</p>
  
  <p>Using .Length does not compile for me either.  I am on an older version of C#, so perhaps that is why.</p>
  
  <p>What is the best practice for getting the length of an IEnumerable?  Should I use Linq's Count() method?  Or is there a better approach.  Does .Length become available on a later version of C#?</p>
  
  <p>Or if I need the count, is an IEnumerable the wrong tool for the job?  Should I be using ICollection instead?  <a href="https://stackoverflow.com/questions/168901/count-the-items-from-a-ienumerablet-without-iterating">Count the items from a IEnumerable&lt;T&gt; without iterating?</a> says that ICollection is a solution, but is it the right solution if you want an IEnumerable with a count?</p>
  
  <p>Obligatory code snippet:</p>
  
  <pre><code>var myEnumerable = IEnumerable&lt;Foo&gt;();
  
  int count1 = myEnumerable.Length; //Does not compile
  
  int count2 = myEnumerable.Count(); //Requires Linq namespace
  
  int count3 = 0; //I hope not
  for(var enumeration in myEnumerable)
  {
      count3++;
  }
  </code></pre>