有没有办法在 c# 中的 int[][] 上使用函数 intersect

Is there a way to use function intersect on int[][] in c#

我有一个数组数组 int[][] = graph,我正在尝试获取两个集合的交集,例如 graph[i]graph[j]

我尝试了这样的操作:graph[i].Intersect(graph[j]) 但我收到的消息类似于

int[] does not contain a definition for Intersect and no extension method Intersect accepting a first argument of type int[] could be found (are you missing a using directive or an assembly reference?)

数组的数组不能使用这个函数吗?

Intersect 正是您正在寻找的方法。你可能省略了使用吗? 这是一个例子。

//using System.Linq;
static void Main(string[] args)
{
    int[][] matrix = new[] { new[] { 0, 1, 2, 3, 3 }, new[] { 2, 3, 4, 5 } };
    var intersection = matrix[0].Intersect(matrix[1]);
    foreach(var integer in intersection)
    {
        Console.WriteLine(integer);
    }
    Console.ReadKey();
}

输出2和3