我们可以从数组中确认的重复项中定义值吗?C# 是如何定义的?

Can we define value from confirmed duplicates in arrays & how C#

我们可以从 3 4 5 数组中的已确认重复项定义值吗?如何定义? 可能这是我寻找重复项的错误路径,但最好询问而不是漫游 遍及我的小脑袋并最终删除它并返回数组矩阵...我需要提取 - 定义重复的 int 值以及它在 5 行中的每一行中存在的时间。总结一下:如何获取重复值“int”以便我可以将其用于以后的检查。

public void Check() 

{
    var result1 = Row1.Any(L1 => Row2.Contains(L1) && Row3.Contains(L1)) == true;

    var result2 = Row1.Any(L1 => Row2.Contains(L1) && Row3.Contains(L1) && Row4.Contains(L1)) == true;

    var result3 = Row1.Any(L1 => Row2.Contains(L1) && Row3.Contains(L1) && Row4.Contains(L1) && Row5.Contains(L1)) == true;

        if(result3 == true) { result1 = false; result2 = false; Debug.Log("Line 5"); }

        if(result2 == true) { result1 = false; Debug.Log("Line 4"); }

        if(result1 == true) { Debug.Log("Line 3"); }
}

如果我没看错你的问题,你只需要 Intersect 扩展方法,例如

int[] id1 = { 44, 26, 92, 30, 71, 38 };
int[] id2 = { 39, 59, 83, 47, 26, 4, 30 };

IEnumerable<int> both = id1.Intersect(id2);

foreach (int id in both)
    Console.WriteLine(id);

/*
 This code produces the following output:

 26
 30
*/

如果目标是找到 交集,即一个或多个数组中存在的所有项目,那么您可以使用 linq Intersect 函数。

var allItemsThatAreInBothRow1AndRow2 = Row1.Intersect(Row2);

并且可以链接

var allItemsInRow1234= Row1
                .Intersect(Row2)
                .Intersect(Row3);
                .Intersect(Row4);