Specifying specific values in an array initialization

44 Views Asked by At

I recall that in C# a notation similar to the one below would be a correct array initializer.

int[] array = new int[3]
{
  [1] = 5;
};

This should initialize the array with all values as default (0 in the case of int) and assign 5 to index 1.

The equivalent would be

int[] array = {0, 5, 0};

This would be correct with a type other than int[] that implements an indexer, but how would I do it with an array?

0

There are 0 best solutions below