Sunday 25 August 2013

Linq - Usage of Union method


In this article we are going to see the usage of union method in Linq, It is same as Union the two collection sets.

For Example 
consider a collection seq1 which have numbers 1,6,3,21
consider a collection seq2 which have numbers 4,6,21,3,5

By union this two collection output is 1,6,3,21,4,5. How we can achieve this using Linq.

var seq1 = new List<int>() {1,6,3,21};

var seq2 = new List<int>() {4,6,21,3,5};

/*union of two sequence */
var diff=seq1.Union(seq2);
foreach (int d in diff)
     Console.WriteLine(d);


Output :
1
6
3
21
4
5

From this article you can learn the usage of Union in Linq.

No comments:

Post a Comment