Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>That's easy to check, without looking at the implementation. Just create a class that implements <code>IList&lt;T&gt;</code>, and put a trace in the <code>Count</code> property:</p> <pre><code> class MyList&lt;T&gt; : IList&lt;T&gt; { private readonly IList&lt;T&gt; _list = new List&lt;T&gt;(); public IEnumerator&lt;T&gt; GetEnumerator() { return _list.GetEnumerator(); } public void Add(T item) { _list.Add(item); } public void Clear() { _list.Clear(); } public bool Contains(T item) { return _list.Contains(item); } public void CopyTo(T[] array, int arrayIndex) { _list.CopyTo(array, arrayIndex); } public bool Remove(T item) { return _list.Remove(item); } public int Count { get { Console.WriteLine ("Count accessed"); return _list.Count; } } public bool IsReadOnly { get { return _list.IsReadOnly; } } public int IndexOf(T item) { return _list.IndexOf(item); } public void Insert(int index, T item) { _list.Insert(index, item); } public void RemoveAt(int index) { _list.RemoveAt(index); } public T this[int index] { get { return _list[index]; } set { _list[index] = value; } } #region Implementation of IEnumerable IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } #endregion } </code></pre> <p>If the <code>Count</code> property is accessed, this code should print "Count accessed":</p> <pre><code>var list = new MyList&lt;int&gt; { 1, 2, 3 }; var array = list.Select(x =&gt; x).ToArray(); </code></pre> <p>But it doesn't print anything, so no, it doesn't keep track of the count. Of course there could be an optimization specific to <code>List&lt;T&gt;</code>, but it seems unlikely...</p>
    singulars
    1. This table or related slice is empty.
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. 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