Set Operators-Intersect


The Intersect operator produces the set intersection of two sequences.


This example prints a list of numbers that are common to two integer arrays. The example uses Intersect to create one sequence that contains the common values shared by both arrays.


 








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 commonNumbers = numbersA.Intersect(numbersB);


    Console.WriteLine("Common numbers shared by both arrays:");

     foreach (var n in commonNumbers)

    {

      Console.WriteLine(n);

    }


    Console.ReadLine();

    }

  }

}





Output:


                    

Aspnet Related Tutorials

...more

New Aspnet Resources

...more

Copyright © 2013 VisualBuilder. All rights reserved