Set Operators-Union


The Union operator produces the set union of two sequences.


This example prints the unique elements of two integer arrays. The example uses the Union method to create a sequence that is a union of the two integer arrays with duplicate elements removed.


 









using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;


namespace ConsoleApplication4

{

class Program

{

   static void Main(string[] args)

   {

     int[] numbersA = { 0, 2, 4, 5, 6, 8, 9 };

     int[] numbersB = { 1, 3, 5, 7, 8 };


     var uniqueNumbers = numbersA.Union(numbersB);


     Console.WriteLine("Unique numbers from both arrays:");

     foreach (var n in uniqueNumbers)

     {

       Console.WriteLine(n);

     }

      Console.ReadLine();

    }

  }

}





Output:


                    

Aspnet Related Tutorials

...more

New Aspnet Resources

...more

Copyright © 2012 VisualBuilder. All rights reserved