views:

25

answers:

2

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

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);
      }
   }              
}
+1  A: 
var result = inListOne.Except(notInListTwo).ToList();
Timwi
Thanks,Final answer: public static void NotIn<T>(List<T> inListOne, List<T> notInListTwo, ref List<T> resultList) { resultList = inListOne.Except(notInListTwo).ToList(); }
@user434290, why not make resultList be the return value instead of using a ref argument ?
driis
+1  A: 

I think you are looking for the Except extension method:

listOne.Except(listTwo);
driis