Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><code>List&lt;T&gt;</code> is a specific implementation of <code>IList&lt;T&gt;</code>, which is a container that can be addressed the same way as a linear array <code>T[]</code> using an integer index. When you specify <code>IList&lt;T&gt;</code> as the type of the method's argument, you only specify that you need certain capabilities of the container. </p> <p>For example, the interface specification does not enforce a specific data structure to be used. The implementation of <code>List&lt;T&gt;</code> happens to the same performance for accessing, deleting and adding elements as a linear array. However, you could imagine an implementation that is backed by a linked list instead, for which adding elements to the end is cheaper (constant-time) but random-access much more expensive. (Note that the .NET <code>LinkedList&lt;T&gt;</code> does <em>not</em> implement <code>IList&lt;T&gt;</code>.)</p> <p>This example also tells you that there may be situations when you need to specify the implementation, not the interface, in the argument list: In this example, whenever you require a particular access performance characteristic. This is usually guaranteed for a specific implementation of a container (<code>List&lt;T&gt;</code> documentation: "It implements the <code>IList&lt;T&gt;</code> generic interface using an array whose size is dynamically increased as required.").</p> <p>Additionally, you might want to consider exposing the least functionality you need. For example. if you don't need to change the content of the list, you should probably consider using <code>IEnumerable&lt;T&gt;</code>, which <code>IList&lt;T&gt;</code> extends.</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