
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
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 Articles
- Intersection of two arrays in Java
- Intersection of Two Arrays in C++
- Intersection of two arrays JavaScript
- Intersection of Two Arrays II in Python
- How to get the intersection of two arrays in MongoDB?
- How to find the intersection of two arrays in java?
- Find Union and Intersection of two unsorted arrays in C++
- How to find intersection between two Numpy arrays?
- Unique intersection of arrays in JavaScript
- The intersection of two arrays in Python (Lambda expression and filter function )
- How to Create an Array using Intersection of two Arrays in JavaScript?
- C program to perform intersection operation on two arrays
- C++ program to find union and intersection of two unsorted arrays
- Intersection of Three Sorted Arrays in C++
- Intersection of three sorted arrays in JavaScript

Advertisements