Note that
in Java an
initialisation via
new
int[4] or via
{1,2,3,4}
are individually legal, but illegal in combination:
int[] row = new int[4]{1,2,3,4}; // illegal Java
In C# initialisers may not be omitted (they can be in C++)
// both of these are illegal C#
int[] row = new int[4]{1,2,3};
int[,] grid = new int[2,3]{ {1,2,3}, {4,5} };
The array size may be completely omitted. For example:
int[] row = new int[]{1,2,3,4}; // legal
int[,] grid = new int[,]{{1,2},{3,4}}; // legal
The new expression may be dropped if the initialisers are specified. This is asyntactic
convenience; underneath the new expression still happens.
int[] row = {1,2,3,4}; // legal
Note that an array creation expression is a legal expression in its own
right:
Func(new[]{1,2,3,4});
Note that the array initialisation syntax applies only to true arrays and not
to the System.Array class that all C# arrays inherit from:
System.Array grid = new int[]{1,2,3,4}; // illegal