title: null check nested objects before using SelectMany
body: <p>I have list of <code>Countries</code> and inside it have list of <code>Places</code>.</p>
  <pre><code>// ...
  
  public IList&lt;ICountriesDTO&gt; Countries { get; set; }
  public class CountriesDTO: ICountriesDTO
  {
      public IEnumerable&lt;IPlacesDTO&gt; Places { get; set; 
  }
  </code></pre>
  <p>I am trying to get list of <code>Places</code> that are not <code>null</code>.</p>
  <pre><code>allPlacesDTO.World.Countries
      .SelectMany(x =&gt; x.Places == null ? null : x.Places)
      .ToList();
  </code></pre>
  <p>But I receive a <code>null exception</code> when <code>Places</code> are <code>null</code> for their <code>Countries</code> <code>object</code>.</p>
  <p>How can I do a <code>null</code> check for <code>Places</code> and just use <code>return</code> statement instead of doing select to <code>null object</code>, similar to what I have below?</p>
  <pre><code>  if (allPlacesDTO.World.Countries.Places == null)
    {
        return;
    }
  </code></pre>
  <hr />
  <h3>Update:</h3>
  <p>My requirement was if there is no places in any of the countries just use the <code>return</code> statement to exit the current function without proceeding further. That was achieved by the accepted answer and <code>Count</code> function.</p>
  <pre><code> var lstAllPlaces = allPlacesDTO.World.Countries
      .Where(x =&gt; x.Places != null)
      .SelectMany(x =&gt; x.Places)
      .ToList();
  
   if (lstAllPlaces.Count() == 0)
   {
       return;
   }
  </code></pre>