

- 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
C# Linq Intersect Method
Find common elements between two arrays using the Intersect() method.
The following are our arrays −
int[] val1 = { 15, 20, 40, 60, 75, 90 }; int[] val2 = { 17, 25, 35, 55, 75, 90 };
To perform intersection.
val1.AsQueryable().Intersect(val2);
Let us see the entire example.
Example
using System; using System.Collections.Generic; using System.Linq; class Demo { static void Main() { int[] val1 = { 15, 20, 40, 60, 75, 90 }; int[] val2 = { 17, 25, 35, 55, 75, 90 }; IEnumerable<int> res = val1.AsQueryable().Intersect(val2); Console.WriteLine("Intersection of both the lists..."); foreach (int a in res) Console.WriteLine(a); } }
Output
Intersection of both the lists... 75 90
- Related Questions & Answers
- Intersect Method in C#
- What are union, intersect and except operators in Linq C#?
- C# Linq Where Method
- C# Linq Distinct() Method
- C# Linq FirstorDefault Method
- C# Linq Reverse Method
- C# Linq Select Method
- C# Linq SelectMany Method
- C# Linq Skip() Method
- C# Linq SkipLast Method
- C# Linq Sum() Method
- C# Linq TakeWhile() Method
- C# Linq ThenBy Method
- C# Linq LastorDefault Method
- C# Linq Zip Method
Advertisements