title: NullReferenceException ERROR in foreach loop using HTMLNode
body: <p>How do I catch the <strong>NullReferenceException</strong> Error in the foreach loop below if 'SelectNodes' returns <strong>NULL</strong>?</p>
  
  <p>I searched on stackoverflow and found mention of the null-coalescing condition (?? condition) that can be used to catch this error, however, I have no idea on what the syntax would be for HTMLNode, or if that's even possible.</p>
  
  <pre><code>foreach (HtmlNode link in imagegallery.DocumentNode.SelectNodes("//a[@href]") )
              {
                  //Do Something
              }
  </code></pre>
  
  <p>How would you cath the NULL EXCEPTION for this loop, or is there a better way of doing this?    </p>
  
  <p>Here is the full code throwing the exception -</p>
  
  <pre><code>    private void TEST_button1_Click(object sender, EventArgs e)
      {
          //Declarations           
          HtmlWeb htmlWeb = new HtmlWeb();
          HtmlAgilityPack.HtmlDocument imagegallery;
  
              imagegallery = htmlWeb.Load(@"http://adamscreation.blogspot.com/search?updated-max=2007-06-27T10:03:00-07:00&amp;amp;max-results=20&amp;amp;start=18&amp;amp;by-date=false");
  
              foreach (HtmlNode link in imagegallery.DocumentNode.SelectNodes("//a[@imageanchor=1 or contains(@href,'1600')]/@href"))
              {
                 //do something
              }
      }       
  </code></pre>