Mega Code Archive

 
Categories / C# Book / 04 LINQ
 

0424 Union

Union returns all the elements of the first sequence, followed by all the elements of the second, but removes any duplicates: using System; using System.Collections; using System.Collections.Generic; using System.Linq; class Program { static void Main() { int[] seq1 = { 1, 2, 3 }; int[] seq2 = { 3, 4, 5 }; IEnumerable<int> union = seq1.Union(seq2); foreach (int i in union) { Console.WriteLine(i); } } } The output: 1 2 3 4 5