title: Hashset "value cannot be null" error
body: <p>I'm trying to execute the follow code and it works fine if myObject is != null but throws a "value cannot be null" error if myObject is null. Ideally, if myObject is null then I'd like to just have the HashSet have a single value of 0.</p>
  
  <pre><code>var ids = new HashSet&lt;int&gt;(myObject.Select(p =&gt; p.ID));
  </code></pre>
  
  <p>I've tried a couple different things. I'm not sure why I thought this would work.</p>
  
  <pre><code>var ids = new HashSet&lt;int&gt;(myObject.Select(p =&gt; p.ID).Where(p =&gt; p != null));
  </code></pre>
  
  <p>and this which seemed like it should work.</p>
  
  <pre><code>var ids = new HashSet&lt;int&gt;(myObject.Select(p =&gt; (p == null) ? 0 : p.ID));
  </code></pre>
  
  <p>Finally this worked but it seems like there's got to be a better way.</p>
  
  <pre><code>var ids = new HashSet&lt;int&gt;(myObject!= null ? myObject.Select(p =&gt; p.ID) : new int[] {0});
  </code></pre>
  
  <p>Anyone have a better way to do this?</p>