Intersect

Ever want to find out what is common in two arrays or lists? The Intersect method is the way to do it.

Basic example

Below is an example of two lists of numbers. In one array, set1, it has a list of numbers in multiples of 10, e.g. 10, 20, 30 and so on. Whilst set2 are in multiples of 5, as in they go up in 5, 10, 15, etc. Performing an Intersect on these lists will identify what is common in both.

Live example: https://dotnetfiddle.net/3LGld2

var set1 = new[] { 10, 20, 30, 40, 50, 60 };
var set2 = new[] { 5, 10, 15, 20, 25, 30, 35 };

var result = set1.Intersect(set2);

//output: 10, 20, 30