Creating Symmetric Array

by May 17, 2012

By default, PowerShell uses jagged arrays. To create conventional symmetric arrays, here's how:

PS> $array = New-Object 'Int32[,]' 2,2

This creates a two-dimensional array of Int32 numbers. Note that each dimension starts with 0, so this array goes from $array[0,0] to $array[1,1].

PS> $array
0
0
0
0
PS> $array[1,1] = 100 PS> $array[1,0] = 100 PS> $array
0
0
100
100

Twitter This Tip! ReTweet this Tip!