title: Remove instances from a list by using LINQ or Lambda?
body: <p>Now I come a stage to get all my data as a list in cache(objects) and my next thing I have to do is to remove some instances from the list.</p>
  
  <p>Normally, I would do removing like this:</p>
  
  <pre><code>List&lt;T&gt; list;
  List&lt;T2&gt; toBeRemovedItems;
  // populate two lists
  foreach(T2 item in toBeRemovedItems)
  {
      list.Remove(delegate(T one) { 
          // build a condition based on item
          // return true or false
      });
  }
  </code></pre>
  
  <p>To be more specific, I actually build or populate toBeRemvoedItems list of a dynamic class (not a formal defined class). For example, the T class is something like MyClass and codes for removing are:</p>
  
  <pre><code>class MyClass&lt;C&gt; {
      public string Value1 { get; set; }
      public int Value2 { get; set; }
      public C ObjectC { get; set; }
  }
  ....
  List&lt;MyClass&lt;C&gt;&gt; list;
  // populate list
  // populate toBeRemovedItems. Here is an example of hard-coded codes:
  var toBeRemovedLItems = new[] {
      new { Value1="a", Value2 = 1},
      new { Value2="x", Value2 = 10},
      ...
  };
  // toBeRemovedItems may be the result of Select from a collection
  foreach(var item in toBeRemovedLItems)
  {
      list.Remove(delegate(MyClass one) {
          return one.Value1 = item.Value1 &amp;&amp; one.Value2 &lt; item.Value2;
      });
  }
  </code></pre>
  
  <p>I tried to search for <code>Remove()</code> method in <code>IEnumerable</code> interface from MSDN, but I cannot find the method of <code>Remove()</code> there (it makes sense that <code>IEnumerable</code> is used just for enumeration). In List class, there are several overloaded <code>Remove(...)</code> methods. I am not sure if there any alternative ways to remove items from a list by using LINQ or Lambda expressions?</p>
  
  <p>By the way, I thought about a way to do a query against a list to get a subset or a new <code>IEnumerable</code> list with Where conditions, similar as moving items from a list. However, I prefer to remove items from my cached list, and there some cases I just cannot reset list property in a class to a new list (private set for example).</p>