1

This

new int[][] { { 1, 2, 7 }, { 3, 4, 5 } }[1][2];

gives a plain int equals to 5 as a result.

I see that this array initialized with some unknown to me method. So, I guess if you will explain what it means and its purpose, everything will become clear.

0

2 Answers 2

4

new int[][] { { 1, 2, 7 }, { 3, 4, 5 } } creates an array. [1] access the second row {3, 4, 5} and then [2] gives you five. It's equivalent to something like

int[][] t = { { 1, 2, 7 }, { 3, 4, 5 } };
int x = t[1][2];

(without t).

Sign up to request clarification or add additional context in comments.

Comments

2

new int[][] { { 1, 2, 7 }, { 3, 4, 5 } } is an array literal. Just as 1 means "integer 1" and "foo" means "String "foo"", new int[][] { { 1, 2, 7 }, { 3, 4, 5 } } means "array of arrays of integers { { 1, 2, 7 }, { 3, 4, 5 } }".

When you have an array, you can index it. Let's call our anonymous array of arrays of integers harvey:

int[][] harvey = new int[][] { { 1, 2, 7 }, { 3, 4, 5 } }

Now harvey[1] is "array of integers { 3, 4, 5}", and if we index that again, harvey[1][2] is the third value of that array, 5.

But wherever you could use harvey, you could just substitute its value; that is the expression you have.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.