2

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"}
            };
2
  • 1
    Your problem exists at the same level: you can't compare directly two string[] arrays... You have to compare them element by element... Commented Mar 24, 2017 at 13:31
  • 1
    And But i can't write access[0] to get "10","16"... In the same way, with a monodimensional array string[] access = { "10, 16" }, you can't write access to get "10", "16" Commented Mar 24, 2017 at 13:32

1 Answer 1

5

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])) { ... }
Sign up to request clarification or add additional context in comments.

3 Comments

Any idea on how to remove the array at access[i] once a match has been found?
I would use a List<string[]> instead of string[][] which would give you access to List.RemoveAt.
Ok Thanks. I will do that!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.