Introduction: This code snippet is Find the common elements in 2 arrays using C#.
Code
- using System;
- using System.Linq;
-
- public class Program
- {
- public static void Main()
- {
-
- int[] array1 ={1, 4, 2, 8, 7};
- int[] array2 ={7, 5, 9, 1, 0, 2, 6};
-
- var intersect = array1.Intersect(array2);
-
- foreach (int value in intersect)
- {
- Console.WriteLine(value);
- }
- }
- }
Output
1
2
7
Demo : https://dotnetfiddle.net/eAfSrx