How can I find the intersecttion between 2 arrays in C#, in a fast way?
Asked
Active
Viewed 2.9k times
2 Answers
23
There's the Intersect extension method on Enumerable. It works on any IEnumerable<T>
including arrays.

Brian Rasmussen
- 114,645
- 34
- 221
- 317
12
Here is an example use of Linq Intersect.
// Assign two arrays.
int[] array1 = { 1, 2, 4 };
int[] array2 = { 2, 3, 4 };
// Call Intersect extension method.
var intersect = array1.Intersect(array2);
foreach (int value in intersect)
{
label1.Text += value + "\n";
}

HasanG
- 12,734
- 29
- 100
- 154