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.

Victor K.
  • 151
  • 4
  • 14

2 Answers2

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).

Elliott Frisch
  • 198,278
  • 20
  • 158
  • 249
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.

Amadan
  • 191,408
  • 23
  • 240
  • 301