title: Atomic List - is this collection threadsafe and fast?
body: <p>I am trying to figure out the best way to have a collection that I will be able to iterate over, add items and remove items all from different threads concurrently.  Performance is critical for the iteration component, but Items will not be added to and removed very often - so add/remove performance is slightly less important.</p>
  
  <p>Here is what I came up with:</p>
  
  <pre><code>public class AtomicList&lt;T&gt; : IEnumerable&lt;T&gt;
  {
      private readonly object Locker = new object();
      private List&lt;T&gt; InternalCollection = new List&lt;T&gt;();
  
      public void Add(T Value)
      {
          lock (Locker)
          {
              List&lt;T&gt; Update = new List&lt;T&gt;(InternalCollection);
              Update.Add(Value);
              InternalCollection = Update;
          }
      }
  
      public void Remove(T Value)
      {
          lock (Locker)
          {
              List&lt;T&gt; Update = new List&lt;T&gt;(InternalCollection);
              Update.Remove(Value);
              InternalCollection = Update;
          }
      }
  
      public IEnumerator&lt;T&gt; GetEnumerator()
      {
          return InternalCollection.GetEnumerator();
      }
  
      IEnumerator IEnumerable.GetEnumerator()
      {
          return GetEnumerator();
      }
  }
  </code></pre>
  
  <p>Are there any drawbacks to doing it like this? Would there be any circumstance when this would not be threadsafe/iterable like I described above?</p>
  
  <p>Also - is there any performance cost for using a foreach and IEnumerable?  Would it be better if I accessed the InternalCollection directly and did a for statement over it?</p>