- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Intersect two lists in C#
Firstly, set two lists.
List<int> val1 = new List<int> { 25, 30, 40, 60, 80, 95, 110 }; List<int> val2 = new List<int> { 27, 35, 40, 75, 95, 100, 110 };
Now, use the Intersect() method to get the intersection between two lists.
IEnumerable<int> res = val1.AsQueryable().Intersect(val2);
Example
using System; using System.Collections.Generic; using System.Linq; class Demo { static void Main() { List<int> val1 = new List<int> { 25, 30, 40, 60, 80, 95, 110 }; List<int> val2 = new List<int> { 27, 35, 40, 75, 95, 100, 110 }; 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... 40 95 110
- Related Articles
- How to join two lists in C#?
- Intersection of Two Linked Lists in C++
- Minimum Index Sum of Two Lists in C++
- Merge two sorted linked lists using C++.
- How to compare two lists for equality in C#?
- How to join or concatenate two lists in C#?
- C# program to find additional values in two lists
- Multiply two numbers represented by Linked Lists in C++
- Dividing two lists in Python
- C# program to find Intersection of two lists
- C# program to concat two or more Lists
- Program to find median of two sorted lists in C++
- Intersect Method in C#
- Merge Two Sorted Lists in Python
- Combining two sorted lists in Python

Advertisements