title: Difference between two lists preserving duplicates
body: <p>I have two lists:</p>
  
  <pre><code>var list1 = new List&lt;string&gt; { "A", "A", "B", C" };
  var list2 = new List&lt;string&gt; { "A", "B" };
  </code></pre>
  
  <p>and I would like to produce a list like</p>
  
  <pre><code>var result = new[] { "A", "C" };
  </code></pre>
  
  <p>Where the list is all the elements from <code>list1</code> removed from <code>list2</code> I don't think there is a Linq extension method for this since <code>Except</code> removes duplicates.</p>
  
  <p>The non-linq way to do this would be:</p>
  
  <pre><code>var tempList = list1.ToList();
  foreach(var item in list2)
  {
      tempList.Remove(item);
  }
  </code></pre>
  
  <p>but I am wondering if there is a Linq extension method that I might have missed.</p>
  
  <p>Edit:</p>
  
  <p>Since there probably aren't any here's an extension method I made.</p>
  
  <pre><code>public static class LinqExtensions
  {
      public static IEnumerable&lt;T&gt; RemoveRange&lt;T&gt;(this IEnumerable&lt;T&gt; source, IEnumerable&lt;T&gt; second)
      {
          var tempList = source.ToList();
  
          foreach(var item in second)
          {
              tempList.Remove(item);
          }
  
          return tempList;
      }
  
      public static IEnumerable&lt;TFirst&gt; RemoveMany&lt;TFirst, TSecond&gt;(this IEnumerable&lt;TFirst&gt; source, IEnumerable&lt;TSecond&gt; second, Func&lt;TSecond, IEnumerable&lt;TFirst&gt;&gt; selector)
      {
          var tempList = source.ToList();
  
          foreach(var item in second.SelectMany(selector))
          {
              tempList.Remove(item);
          }
  
          return tempList;
      }
  }
  </code></pre>
  
  <p>Usage:</p>
  
  <pre><code>list1.RemoveRange(list2)
  </code></pre>