title: Cannot add items to an IList/List being casted from an IEnumerable
body: <p>I'm trying to create a small proof-of-concept application for my boss, however the code I've created that simulates what he's trying to pull off isn't working.</p>
  
  <pre><code>for (int i = 0; i &lt; 5000; i++)
  {
       ((IList&lt;string&gt;) obj2.Stuff).Add("Iteration " + i.ToString());
  }
  </code></pre>
  
  <p>I'm trying to pull this off all in one line because this is what his code looked like the other day in the framework we're working on. Anywho when the code above executes, I get a runtime error saying "Collection was of a fixed-size". And when I try casting to a List instead of an IList, I get an InvalidCastException saying "Unable to cast object of type 'System.String[]' to type 'System.Collections.Generic.List`1[System.String]'."</p>
  
  <p>Anybody have any ideas on how I can pull off a single-line cast to add an item to the IEnumerable or help me figure out a way around the two errors I keep getting? Thanks in advance.</p>
  
  <p><strong>EDIT</strong> (4/19/2011 10:49AM EST)
  I'm adding more code to help people out -- probably should've done this earlier. Sorry.</p>
  
  <p>Program.cs:</p>
  
  <pre><code>        #region Cast Test
          Class1 obj2 = new Class1();
          obj2.Stuff = Enumerable.Empty&lt;string&gt;();
  
          Console.WriteLine("Cast - Start Time: " + 0 + "ms");
  
          Stopwatch stopwatch2 = new Stopwatch();
          stopwatch.Start();
  
          for (int i = 0; i &lt; 5000; i++)
          {
              ((IList&lt;string&gt;) obj2.Stuff).Add("Iteration " + i.ToString());
          }
  
          stopwatch2.Stop();
          Console.WriteLine("Cast - Stop Time: " + stopwatch2.ElapsedMilliseconds.ToString() + "ms");
          #endregion
  </code></pre>
  
  <p>Class1.cs:</p>
  
  <pre><code>public class Class1
  {
      private IEnumerable&lt;string&gt; stuff;
  
      public IEnumerable&lt;string&gt; Stuff
      {
          get { return stuff; }
          set { stuff = value; }
      }
  }
  </code></pre>