On 03/23/2012 09:10 PM, Andrej Mitrovic wrote:
On 3/23/12, Timon Gehr<timon.g...@gmx.ch>  wrote:
Maybe you are also missing that this is valid code:
int[] a = [1 : 2, 3 : 4];

What is this syntax for and how is it used? It creates '[0, 2, 0, 4]',
which is puzzling to me.

It creates an array from key-value pairs. a[1] will be 2 and a[3] will be 4. Unspecified entries are default-initialized. It can be quite useful for building lookup tables.

Another reason why array initializers are different from array literals:
struct S{int a,b,c;}
S[] sarr = [{a: 1, b: 2, c: 3}, {a: 4, b: 5, c: 6}];

Reply via email to