title: Enumerable.Empty to List
body: <p>If I for example have this method:</p>
  
  <pre><code>IEnumerable&lt;int&gt; GetRandomNumbers()
  {
      // {Codes that generate numbers as List&lt;int&gt;}
      if(generationFails == true)
      {
          return Enumberable.Empty&lt;int&gt;(); // I do this to signal that we have an error
      }
      return numbers;
  }
  </code></pre>
  
  <p>In the calling method I do:</p>
  
  <pre><code>IEnumerable&lt;int&gt; AddNumber(int number)
  {
      var random = GetRandomNumbers();
      var randomList = random  as IList&lt;int&gt; ?? random.ToList(); // Run ToList only if needed
      randomList.Add(number); 
      return randomList;
  }
  </code></pre>
  
  <p>and when generation fails I get an exception "[NotSupportedException: Collection was of a fixed size.]".</p>
  
  <p>This is due to the fact that the Enumerable empty is an IList so the .ToList() is not run and I am then trying to add to a fixed Enumberable.Empty. Am I wrong in thinking that this is bad design, an object that inherits IList (where Add is defined) should support Add? </p>
  
  <p>Am I forced to do <code>var randomList = random.ToList()</code> or stop using <code>Enumberable.Empty</code>? Is there some better way?</p>
  
  <p><strong>Update:</strong>
  I think I was unclear in my example. I wish to swallow (or log) the error but allow operation to continue without crashing. My  comment "I do this to signal that we have an error" was meant to tell other developers reading the code that this is an abnormal behavior. </p>
  
  <p>The <a href="https://stackoverflow.com/a/5968798/116460">answer</a> to the question Tim linked was what I was getting at. Seems that we just don't have an interface for constant collections so <code>IList</code> is used.</p>