Intersect two arrays

浪尽此生 提交于 2019-11-29 05:47:58

There's the Intersect extension method on Enumerable. It works on any IEnumerable<T> including arrays.

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