Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <ul> <li><p>Length is a fixed property, e.g. of a single dimensional array or string. So there's never a count operation necessary (multi-dimensional arrays have a size of all dimensions multiplied). O(1) operation here means that retrieval time is always the same, no matter how many elements there are. A linear search would (opposed to this) be O(n).</p></li> <li><p>The Count property on ICollections (List and List&lt;T&gt;, for example) can change, so it has either to be updated on Add/Remove operations, or when Count is requested after the Collection has changed. Depends on the implementation of the object.</p></li> <li><p>The Count() method of LINQ basically iterates EVERY TIME it is called (except when the object is an ICollection type, then the ICollection.Count property is requested).</p></li> </ul> <p>Note that IEnumerables are often not already defined object collections (like lists, arrays, hashtables etc.), but link to background operations, which generate results whenever they are requested (called deferred execution).</p> <p>Typically, you have an SQL like LINQ statement like this (the typical application of deferred execution):</p> <pre><code>IEnumerable&lt;Person&gt; deptLeaders = from p in persons join d in departments on p.ID equals d.LeaderID orderby p.LastName, p.FirstName select p; </code></pre> <p>Then, there's code like this:</p> <pre><code>if (deptLeaders.Count() &gt; 0) { ReportNumberOfDeptLeaders(deptLeaders.Count()); if (deptLeaders.Count() &gt; 20) WarnTooManyDepartmentLeaders(deptLeaders.Count()); } </code></pre> <p>So, when a warning for too many Department Leaders is issued, .NET goes FOUR TIMES through the persons, checks them against the department leaders, sorts them by name and then counts the result objects. </p> <p>And this is only when persons and departments are preset value collections, not queries themselves.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

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