user434290
user434290

Reputation: 63

Using Generics with LinqToObjects and NOT IN

I want to turn the follow function into a Lambda. After working on it for 45 minutes, I decided to go old school. How would one do this with a Lambda?

public static void NotIn<T>(List<T> inListOne, List<T> notInListTwo,ref List<T> resultList)
{

   resultList = new List<T>();

   foreach (T item in inListOne)
   {
      if (notInListTwo.Contains(item))
      {
          resultList.Add(item);
      }
   }              
}

Upvotes: 0

Views: 119

Answers (2)

driis
driis

Reputation: 164341

I think you are looking for the Except extension method:

listOne.Except(listTwo);

Upvotes: 1

Timwi
Timwi

Reputation: 66604

var result = inListOne.Except(notInListTwo).ToList();

Upvotes: 1

Related Questions