Azuraith
Azuraith

Reputation: 1050

How can i compare arrays in two jagged arrays C#

Ok so i have 2 jagged arrays, i want to loop through them and compare each array to every array in the other jagged array. So in this example i want to return true when access[1] == visual[0].

But it seems i cannot explicitly compare arrays in the jagged arrays. How can i reference the arrays as a whole and not only the elements within those arrays? By this i mean if i write access[0][0] i will get "10". But i can't write access[0] to get "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"}
            };

Upvotes: 2

Views: 1310

Answers (1)

Andrew Jenkins
Andrew Jenkins

Reputation: 1609

But i can't write access[0] to get "10","16"

You can. But to compare the elements you need to use Enumerable.SequenceEqual.

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

Upvotes: 5

Related Questions