开发者

Using Generics with LinqToObjects and NOT IN

开发者 https://www.devze.com 2023-01-13 19:55 出处:网络
I want to turn the follow function into a Lambda.After working on it for45 minutes, I decided to go old school.How would one do this with a Lambda?

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);
      }
   }              
}


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


I think you are looking for the Except extension method:

listOne.Except(listTwo);
0

精彩评论

暂无评论...
验证码 换一张
取 消