- 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 Method in C#
Use the Intesect method to get the common elements −
Create lists −
var list1 = new List{99, 87}; var list2 = new List{56, 87, 45, 99};
Now, use the Intersect() method to get the common elements from the above list −
list1.Intersect(list2);
Here is the complete code −
Example
using System.Collections.Generic; using System.Linq; using System; public class Demo { public static void Main() { // two lists var list1 = new List<int>{99, 87}; var list2 = new List<int>{56, 87, 45, 99}; // common values var res = list1.Intersect(list2); foreach(int i in res) { Console.WriteLine(i); } } }
Output
99 87
- Related Articles
- C# Linq Intersect Method
- Intersect two lists in C#
- What are union, intersect and except operators in Linq C#?
- Dictionary.ContainsKey() Method in C#
- Dictionary.ContainsValue() Method in C#
- Array.ConstrainedCopy() Method in C#
- Char.IsSymbol() Method in C#
- Char.IsUpper() Method in C#
- Array.Clear() Method in C#
- CharEnumerator.Clone() Method in C#
- CharEnumerator.Dispose() Method in C#
- Dictionary.Clear Method in C#
- Char.IsWhiteSpace() Method in C#
- Math.DivRem() Method in C#
- Math.Exp() Method in C#

Advertisements