Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It is considered good practice to work with the highest possible class in the hierarchy. So if you only need to loop through the values you should only expose <code>IEnumerable&lt;T&gt;</code>:</p> <pre><code>IEnumerable&lt;Facility&gt; Facilities = new List&lt;Facility&gt;(); // now you can foreach over the facilities or chain with LINQ </code></pre> <p>If you need indexer access you could use <code>IList&lt;Facility&gt;</code></p> <pre><code>IList&lt;Facility&gt; Facilities = new List&lt;Facility&gt;(); // in addition to looping now you can access facilities by index // and you can also add and remove facilities </code></pre> <p>The idea behind exposing the highest possible class/interface in the hierarchy when designing some API is that this way you are hiding the implementation details that you are using a <code>List&lt;T&gt;</code>. If you tomorrow you invent a <code>HyperSpecialListWhichIsVeryFast&lt;T&gt;</code> which implements the contract that you agreed upon with the consumer of the API, this consumer doesn't need to change anything in his code. He doesn't care. He works with <code>IEnumerable&lt;T&gt;</code> because all he needs is to loop for example. And thanks to your new list his code will run faster without him needing to change anything.</p> <p>But using a non-generic à la .NET 1.0 weakly typed collections which are in the history books now is like voodoo magic:</p> <pre><code>IList Facilities = new List&lt;Facility&gt;(); </code></pre> <p>Cannot think of any reason why this would be useful. Downcasting to a non-generic version will force the client to cast in order to access the underlying type <code>T</code>. This way he is loosing all the compile-time safety that generics provide.</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. 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