Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
C# program to find common values from two or more Lists
Create more than one list −
// two lists
var list1 = new List<int>{3, 4};
var list2 = new List<int>{1, 2, 3};
Now, use the Intersect() method to get the common values −
var res = list1.Intersect(list2);
The following 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>{3, 4};
var list2 = new List<int>{1, 2, 3};
// common values
var res = list1.Intersect(list2);
foreach(int i in res) {
Console.WriteLine(i);
}
}
}
Output
3
Advertisements
