In LINQ, the Union method or operator combines multiple collections into a single collection and returns the resultant collection with unique elements.
Following is the pictorial representation of the LINQ union method.
The union method will combine the collections into a single collection and return unique elements by removing duplicate elements.
Following is the syntax of using the union method to get unique elements from multiple collections.
C# Code
VB.NET Code
If you observe the above syntax, we combine two collections to get the result as a single collection using the union method.
Following is the example of using the LINQ union method.
C# Code
VB.NET Code
If you observe the above example, we are combining two collections, “count1” and “count2” using the union method to get unique elements from both collections.
Following is the result of the LINQ union method example.
This is how we can use the LINQ union method in c#, vb.net to get unique elements from collections.