Reference Vs Value array

  • Thread starter Thread starter Neil Chambers
  • Start date Start date
N

Neil Chambers

I'm currently using multidimensional arrays in PoSH by assigning values
to index positions. I'm doing this because AFAIK there is no way to
initialise an array simply with the 'number' of dimensions required.
So, for example, I would initialise an array with 3 x 2 dimensions
thusly:

$myArray = @((1,2),(3,4),(5,6))

$myArray[2][0]
5

Is there a way to state the number of dimensions required without
populating values? (and then, of course, assign values as required?)

Cheers,
n
 
Neil,

In C#, you can just do:

int[,] myArray = new int[3, 2];

And it will initialize a 3 x 2 array. You would access it like this:

int myInt = myArray[0, 0] // Gives you 1.
myInt = myArray[2, 0] // Gives you 5.

Hope this helps.
 
Back
Top