Reference Vs Value array

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
 
N

Nicholas Paldino [.NET/C# MVP]

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top