title: Removing All Nulls From Collections
body: <p>I'm having to deal with collections of data being thrown at my application from data sources out of my control.  Some of these collections contain nulls which I would prefer to filter out as soon as they hit my code rather than scatter null checking code all over the place.  I want to do this in a reusable generic fashion and have written this method to do it:</p>
  
  <pre><code>    public static void RemoveNulls&lt;T&gt;(this IList&lt;T&gt; collection) where T : class
      {
          for (var i = 0; i &lt; collection.Count(); i++)
          {
              if (collection[i] == null)
                  collection.RemoveAt(i);
          }
      }
  </code></pre>
  
  <p>I know on the concrete List class there is the <code>RemoveAll()</code> method that could be used like:</p>
  
  <pre><code>collection.RemoveAll(x =&gt; x == null);
  </code></pre>
  
  <p>But a lot of the return types are interface based (IList/ IList ...) rather than concrete types.</p>