LINQ to Object compares two lists of integers for different values

I accept C # and VB.NET suggestions, although I am writing an application in VB.NET

I have two lists of intergers

  • List1 {1,2,3,5}
  • List2 {2,4,6,7}

I want to have a new List3 {4,6,7}, which consists of List2 elements that are not in List1. I know that I can write a good For Each loop for this, but I want it to be done in LINQ. I searched for such methods in Enumerable Methods , but I cannot find it.

Is there a LINQ way?

+3
source share
2 answers
List2.Except(List1)
+9
source
var List3 = List2.Except(List1);
+3
source

Source: https://habr.com/ru/post/1765522/


All Articles