Intersect two arrays

半世苍凉 提交于 2019-12-18 04:34:42

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!