title: Fastest implementation of IList<T>/ICollection<T> in terms of adding/removing an element
body: <p>I've spotted some really nasty code in one class (let's call it <strong>MyClass</strong>) that uses <strong>List of T.Add/Remove</strong> methods extensively. Also the same class exposes that collection as property with IList of T type, so changing the type would involve some refactoring.</p>
  
  <p>Also, that MyClass collection is used as a container for event listener objects, so client code just subscribes (adds itself to collection) and unsubscribes (removes itself from collection). Order doesn't matter, whether it's start/middle/end of the list. </p>
  
  <p>In order to improve performance, I would like to replace internal implementation detail, replace List of T with.... I don't know what. I tried LinkedList of T, but it does not implement IList of T. I looked at <a href="http://msdn.microsoft.com/en-us/library/5y536ey6.aspx" rel="nofollow">IList of T at MSDN</a>, but there's no list of classes that implement IList, so I could compare documentations.</p>
  
  <p>Another thing is that I tried to change IList of T to ICollection of T, and that could be a solution (as client code of <strong>MyClass</strong> uses Add/Remove methods, so no refactoring is necessary) but interesting thing happened:</p>
  
  <pre><code>        LinkedList&lt;string&gt; list = new LinkedList&lt;string&gt;();
          list.Add("test");
  </code></pre>
  
  <p>This code does not compile as I get an error:</p>
  
  <blockquote>
    <p>'System.Collections.Generic.LinkedList' does not contain a
    definition for 'Add' and no extension method 'Add'</p>
  </blockquote>
  
  <p>But when I changed it to:</p>
  
  <pre><code>        ICollection&lt;string&gt; list = new LinkedList&lt;string&gt;();
          list.Add("test");
  </code></pre>
  
  <p>then I worked. Could you explain why first sample didn't compile + tell what is the fastest implementation of IList of T in .NET Framework in terms of Adding/Removing items?</p>
  
  <p>Thanks.</p>