title: How to handle no matches case in List.First in c#?
body: <p>In <a href="http://msdn.microsoft.com/en-us/library/bb291976.aspx" rel="nofollow">IEnumerable.First</a> function, how do I handle the case if there are no matches? Currently it just crashes...</p>
  
  <pre><code>MySPListItem firstItem = itemCollection.First(item =&gt; !item.isFolder);
  if (firstItem != null)
  {
      TreeNode firstNode = GetNodeByListItem(my_treeview.Nodes, firstItem, ReportObject);
      if (firstNode != null)
      {
          ReportObject.log("Selecting the first PDF");
          selectPDF(my_treeview, firstNode, queryStr_param);
      }
  }
  </code></pre>
  
  <p>Error Message:</p>
  
  <blockquote>
    <p>Sequence contains no matching element<br>
    Stacktrace:    at System.Linq.Enumerable.First[TSource](IEnumerable<code>1 source, Func</code>2
    predicate)</p>
  </blockquote>