In LINQ, the Except method or operator is useful for returning only the elements from the first collection that are not present in the second collection.
Following is the pictorial representation of the LINQ Except method.
As discussed, it returns elements only from the first collection, which do not exist in the second collection.
Following is the syntax of using the LINQ Except method to get elements from the first list which do not exist in the second list.
C# Code
VB.NET Code
If you observe the above syntax, we are comparing two lists, “arr1” and “arr2” and getting the elements using the Except method.
The following is the LINQ Except method example to get elements from the first collection.
C# Code
VB.NET Code
If you observe the above example, we applied the Except method to “arr1” and “arr2” to get elements from the first collection that do not exist in the second collection.
Following is the result of the LINQ Except method example.
This is how we can use the LINQ Except method to get elements from the first collection that do not exist in the second collection.