C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
Note: Each array has three numbers in it. Both arrays have the numbers 2 and 3, and one other number.
Result: The results show that the Intersect method returns these exact numbers: 2 and 3. These are the intersecting numbers.
ArrayTip: Intersect here compares elements in the default way for their type. For ints, a simple numeric comparison for equality is done.
Int, uintC# program that uses Intersect extension method
using System;
using System.Linq;
class Program
{
static void Main()
{
// Assign two arrays.
int[] array1 = { 1, 2, 3 };
int[] array2 = { 2, 3, 4 };
// Call Intersect extension method.
var intersect = array1.Intersect(array2);
// Write intersection to screen.
foreach (int value in intersect)
{
Console.WriteLine(value);
}
}
}
Output
2
3