问题
How can I find the intersecttion between 2 arrays in C#, in a fast way?
回答1:
There's the Intersect extension method on Enumerable. It works on any IEnumerable<T>
including arrays.
回答2:
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";
}
来源:https://stackoverflow.com/questions/4248433/intersect-two-arrays