title: Null Exception when using .ToList().ForEach() in C#
body: <p>I am using HtmlAgilityPack to parse some data and writing statements like the below one to remove unwanted contents - </p>
  
  <pre><code>doc.DocumentNode.SelectNodes("//ul").ToList().ForEach(a =&gt; a.Remove());
  </code></pre>
  
  <p>This works well when there's <code>&lt;ul&gt;</code> element present in the HTML document. However, if there's no <code>&lt;ul&gt;</code> element, I get a <strong>Value cannot by null</strong> exception when converting it into .ToList(). </p>
  
  <p>I do not want to use the following - </p>
  
  <pre><code>doc.DocumentNode.SelectNodes("//ul")== null ? null : doc.DocumentNode.SelectNodes("//ul").ToList().ForEach(a =&gt; a.Remove());
  </code></pre>
  
  <p>What elegant alternatives do I have?</p>