title: Does an empty array in .NET use any space?
body: <p>I have some code where I'm returning an array of objects.</p>
  <p>Here's a simplified example:</p>
  <pre><code>string[] GetTheStuff() {
      List&lt;string&gt; s = null;
      if( somePredicate() ) {
          s = new List&lt;string&gt;(); // imagine we load some data or something
      }
      return (s == null) ? 
          new string[0] :
          s.ToArray();
  }
  </code></pre>
  <p>The question is, how expensive is the <code>new string[0]</code> ?<br />
  Should I just return null and make the caller accept null as a valid way of indicating &quot;nothing was found&quot;?</p>
  <p>NB: This is being called in a loop which gets run hundreds and hundreds of times, so it's one of the few cases where I think this kind of optimiziation is not actually 'premature'.</p>
  <p>PS: And even if it was premature, I'd still like to know how it works :-)</p>
  <h3>Update:</h3>
  <p>Initially when I asked if it used any space, I was thinking of things from the 'C/C++' point of view, kind of like how in C, writing <code>char a[5];</code> will allocate 5 bytes of space on the stack, and <code>char b[0];</code> will allocate 0 bytes.</p>
  <p>I realise this is not a good fit for the .NET world, but I was curious if this was something that the compiler or CLR would detect and optimize out, as a non-resizeable array of size zero really shouldn't (as far as I can see?) require any storage space.</p>