Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
For me, it was not apparent to create multiple dimensional or jagged arrays in Powershell. I tried the following command, but it only made a single dimensional array:
$b = ((‘a’,’a’))
$b.Count
2
Bruce Payette gave me the answers for this basic question.
Here is how to create multiple arrays:
$x = new-object "int32[,]" 10,10
$x.rank
$x[0,5] = 13
$x[0,5]
13
And, here is how to create jagged arrays:
$a = (1,2,3),("a","b","c"),([char[]]"Hello")
$a[0]
1
2
3
$a[0][1]
2
$a[1][1]
b
$a[2][4]
o
$a[2][1..3]
Or..you can use unary comma operator as follows:
$a = ,(1,2)
$a.count
1
$a[0]
1
2
$a[0].count
2
Comments
- Anonymous
July 17, 2006
PingBack from http://microsoft.wagalulu.com/2006/07/17/how-to-create-multiple-or-jagged-arrays-in-powershell/ - Anonymous
March 24, 2008
PingBack from http://frankthefrank.info/entry.php?id=kwws%3d22pvgq1whfkqhwzhe61rufvzhe1frp2%7cmkrqj2dufklyh2533923%3a24%3b299%3b%3a8%3a1dvs%7b