Note that there are some explanatory texts on larger screens.

plurals
  1. POCustom Collection using IEnumerable vs ICollection vs IList
    primarykey
    data
    text
    <p>I need to design my own custom <code>GenericCollection</code> class. Now i have plenty of options to derive it using <code>IEnumerable</code>, <code>ICollection</code>, and <code>IList</code>, where later offers some added functionalities.</p> <p>I am little confused that if i go with <code>IEnumerable&lt;T&gt;</code> i might require declaring the object to actually hold the collection like in this case <code>_list</code>.</p> <pre><code>public class GenericCollection&lt;T&gt; : IEnumerable&lt;T&gt; { private List&lt;T&gt; _list; //... } </code></pre> <p>But if i go with <code>ICollection&lt;T&gt;</code> or <code>IList&lt;T&gt;</code>, i do not require to declare the <code>List</code> object as it is implicitly available.</p> <pre><code>public class GenericCollection&lt;T&gt; : IList&lt;T&gt; { // no need for List object //private List&lt;T&gt; _list; //... } </code></pre> <p>What is the difference between these two approaches with respect to <em>performance</em>?</p> <p>In which scenario each one is preferred especially when it comes to designing your own collection. I am interested in the light weight collection with good performance. I think this can be achieved using <code>IEnumerable&lt;T&gt;</code> but how exactly along with some strong reasons to go with it?</p> <p>I have reviewed some existing posts but none is giving required information.</p> <p><a href="https://stackoverflow.com/questions/9855693/ilist-vs-icollection-vs-collection">Returning &#39;IList&#39; vs &#39;ICollection&#39; vs &#39;Collection&#39;</a></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.
 

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