我怎样才能比较两个锯齿状数组中的数组C#

时间:2017-03-24 13:25:02

标签: c# arrays compare comparison jagged-arrays

好吧我有2个锯齿状数组,我想循环遍历它们并将每个数组与另一个锯齿状数组中的每个数组进行比较。 所以在这个例子中,我想在访问[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"}
            };

1 个答案:

答案 0 :(得分:3)

  

但是我不能写访问[0]来获得“10”,“16”

你可以。但要比较您需要使用的元素https://fishshell.com/docs/current/tutorial.html#tut_command_substitutions

if (Enumerable.SequenceEqual(access[1], visual[0])) { ... }
相关问题