簡體   English   中英

我如何比較兩個鋸齒狀數組中的數組C#

[英]How can i compare arrays in two jagged arrays C#

好的,所以我有2個鋸齒狀數組,我想遍歷它們並將每個數組與另一個鋸齒狀數組中的每個數組進行比較。 因此,在此示例中,當access [1] == visual [0]時,我想返回true。

但似乎我不能顯式比較鋸齒狀數組中的數組。 我如何引用整個數組,而不僅是引用這些數組中的元素? 我的意思是,如果我寫access[0][0]我將得到"10" 但是我無法寫入access[0]來獲取"10","16"

string[][] access = new string[][] {
                    new string[] {"10","16"},
                    new string[] {"100","20"},
                    new string[] {"1010","2"},
                    new string[] {"1011","1"}
                };

string[][] visual = new string[][] {
                new string[] {"100","20"},
                new string[] {"101","36"},
                new string[] {"101","37"},
                new string[] {"101","38"}
            };

但是我無法寫入access [0]來獲取“ 10”,“ 16”

您可以。 但是要比較元素,您需要使用Enumerable.SequenceEqual

if (Enumerable.SequenceEqual(access[1], visual[0])) { ... }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM