In LINQ, the Intersect method or operator is helpful to return common elements from both collections.
Following is the pictorial representation of the LINQ intersect method.
The LINQ intersect method will combine the collections into a single collection and return only matching elements from the collections.
Following is the syntax of the intersect method to get matching elements from multiple collections.
C# Code
VB.NET Code
If you observe the above syntax, we are combining two collections to get the result as a single collection using the intersect method.
Following is the example of using the LINQ intersect method.
C# Code
VB.NET Code
If you observe the above example, we are combining two collections, “count1”, “count2” using the Intersect method to get common elements from both collections.
Following is the result of the LINQ intersect method example.
This is how we can use LINQ intersect method in c#, vb.net to get matching elements from the collections.