title: LINQ to return null if an array is empty
body: <pre><code>public class Stuff
  {
    public int x;
    // ... other stuff
  }
  </code></pre>
  
  <p>I have a <code>IEnumerable&lt;Stuff&gt;</code> and I want to build a <code>int[]</code> of all of the <code>x</code> properties of all the <code>Stuff</code> objects in the collection.</p>
  
  <p>I do:</p>
  
  <pre><code>IEnumerable&lt;Stuff&gt; coll;
  // ...
  var data = coll.Select(s =&gt; s.x).ToArray();
  </code></pre>
  
  <p>What I want is a null array rather than a <code>int[0]</code> if the collection is empty.  In other words, if <code>!coll.Any()</code>, then I want <code>data = null</code>.  (My actual need is that <code>coll</code> is an intermediate result of a complex LINQ expression, and I would like to do this with a LINQ operation on the expression chain, rather than saving the intermediate result)</p>
  
  <p>I know that <code>int[0]</code> is more desirable than <code>null</code> in many contexts, but I am storing many of these results and would prefer to pass around <code>nulls</code> than empty arrays.</p>
  
  <p>So my current solution is something like:</p>
  
  <pre><code>var tmp = coll.Select(s =&gt; s.x).ToArray();
  int[] data = tmp.Any() ? tmp : null;
  </code></pre>
  
  <p>Any way to do this without storing <code>tmp</code>?</p>
  
  <p><strong>EDIT</strong>: The main question is how to do this without storing intermediate results.  Something like <code>NULLIF()</code> from <code>T-SQL</code> where you get back what you passed in if the condition is false, and <code>NULL</code> if the condition is true.</p>