title: Lambda or LinQ expression to remove certain objects from List
body: <p>I have a cart.Lines List and want to remove all items where quantity == 0</p>
  
  <p>This is a list that holds collection of CartLine objects:</p>
  
  <pre><code>public class Cart
  {
      private IList&lt;CartLine&gt; lines = new List&lt;CartLine&gt;();
      public IList&lt;CartLine&gt; Lines { get { return lines; } set { lines = value; } }
  }   
  
  public class CartLine
  {
      Product Product {get; set;}
      int Quantity {get; set;}
  
  }
  </code></pre>
  
  <p>So something like:</p>
  
  <pre><code>cart.Lines.RemoveAll(x =&gt; x.Quantity == 0)
  </code></pre>
  
  <p><strong>I only get Remove and RemoveAt, not RemoveAll !</strong></p>
  
  <p>Also can't remove in a foreach loop, get error:
  Collection was modified; enumeration operation may not execute.</p>
  
  <p><strong>I have now managed to do it with this code, surely there must be something more efficient ?</strong></p>
  
  <pre><code>var myList = cart.Lines.ToList();
  myList.RemoveAll(x =&gt; x.Quantity == 0);
  cart.Lines = myList;
  </code></pre>
  
  <p><strong>Okay Problem solved!Thanks guys, this here does it:</strong></p>
  
  <p><strong>cart.Lines = cart.Lines.Where(x => x.Quantity != 0);</strong></p>