Find The Common Elements In 2 Arrays Using C#

Introduction: This code snippet is Find the common elements in 2 arrays using C#.
 
Code 
  1. using System;  
  2. using System.Linq;  
  3.   
  4. public class Program  
  5. {  
  6.     public static void Main()  
  7.     {  
  8.       
  9.         int[] array1 ={1, 4, 2, 8, 7};  
  10.         int[] array2 ={7, 5, 9, 1, 0, 2, 6};  
  11.         // Call Intersect extension method.  
  12.         var intersect = array1.Intersect(array2);  
  13.           
  14.         foreach (int value in intersect)  
  15.         {  
  16.             Console.WriteLine(value);  
  17.         }  
  18.     }  

Output

1
2
7
 
Demo : https://dotnetfiddle.net/eAfSrx