Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The key difference between the ICollection family and the IEnumerable family is the absence of certainty as to the count of items present (quite often the items will be generated/loaded/hydrated as needed) - in some cases, an Enumerable may not ever finish generating results, which is why the Count is missing.</p> <p>Deriving and adding a Count is possible depending on your requirements, but it goes against this spirit, which is the purpose of ICollection - a collection of stuff that's all there.</p> <p>Another way might be to use the System.Linq.Enumerable.Count method, i.e.</p> <pre><code>using System.Linq; class X { void Y(IEnumerable&lt;int&gt; collection) { int itemCount = collection.Count(); } } </code></pre> <p>or use the (System.Linq.Enumerable) .ToList() to pull all the items from the enumerator into a Collection and work from there.</p> <p>(Also to answer your comment before having 50 rep:- the ".Count()" bit is a call to an extension method on the extension class System.Linq.Enumerable - the extension method is available on all things that derive from IEnumerable because the code has a "using System.Linq" which brings the extension methods in all classes in that namespace into scope - in this case its in the class Enumerable. If you're in VS, pressing F12 will bring you to the definition of S.L.Enumerable. BTW C# In Depth is a fantastic book for learning LINQ properly - its a page turner thats really helps you get the whole picture compared to learning the bits of LINQ piece by piece)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload