我們可以從 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"); }
}
uj5u.com熱心網友回復:
如果我正確閱讀了您的問題,您只需要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
*/
uj5u.com熱心網友回復:
如果目標是找到交集,即一個或多個陣列中存在的所有專案,那么您可以使用 linq Intersect函式。
var allItemsThatAreInBothRow1AndRow2 = Row1.Intersect(Row2);
而且可以鏈式
var allItemsInRow1234= Row1
.Intersect(Row2)
.Intersect(Row3);
.Intersect(Row4);
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/466471.html
下一篇:如何在linq和C#中使用條件或
