

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Intersection of two arrays in C#
To get intersection of two arrays, use the Intersect method. It is an extension method from the System.Linq namespace.
The method returns the common elements between the two arrays.
Set the two arrays first −
int[] arr1 = { 44, 76, 98, 34 }; int[] arr2 = { 24, 98, 44, 55, 47, 86 };
Now use the Intersect on both the arrays −
Arr1.Intersect(arr2);
The following is the complete code −
Example
using System; using System.Linq; class Program { static void Main() { int[] arr1 = { 44, 76, 98, 34 }; int[] arr2 = { 24, 98, 44, 55, 47, 86 }; var intersect = arr1.Intersect(arr2); foreach (int res in intersect) { Console.WriteLine(res); } } }
Output
44 98
- Related Questions & Answers
- Intersection of two arrays JavaScript
- Intersection of two arrays in Java
- Intersection of Two Arrays in C++
- Intersection of Two Arrays II in Python
- How to find the intersection of two arrays in java?
- How to get the intersection of two arrays in MongoDB?
- Find Union and Intersection of two unsorted arrays in C++
- How to find intersection between two Numpy arrays?
- Unique intersection of arrays in JavaScript
- C++ program to find union and intersection of two unsorted arrays
- C program to perform intersection operation on two arrays
- The intersection of two arrays in Python (Lambda expression and filter function )
- Finding intersection of multiple arrays - JavaScript
- Intersection of Three Sorted Arrays in C++
- Intersection of three sorted arrays in JavaScript
Advertisements