Wednesday, December 1, 2010

Creating a multidimensional strongly typed array in Powershell

When getting stuck for a short while trying to figure out how to create a strongly typed multidimensional array in Powershell I tried to find an example on the net just to find that there simply just is no example of it to be found. Maybe it's too easy? The Technet page on the New-Object cmdlet gave me what I needed.

The way I later on created my two dimensional array was like this:

$d = New-Object 'Object[,]' 10, 20
This is however created as an Object array while I needed int. I changed the code to this:

$d = New-Object 'Int32[,]' 10, 20
Then I thought that it should be possible to streamline it a bit so I got this:

$d = Int32[,] 10, 20
Simple enough. When I see it, I wonder why I couldn't figure it out quicker.