Powershell array assignment assigns variable, not value?

后端 未结 2 727
遥遥无期
遥遥无期 2021-01-13 02:05

I have an example of a program that creates an array, and then attempts to assign the value of that array multiple times into another array as a multidimensional array.

2条回答
  •  萌比男神i
    2021-01-13 02:26

    Be careful in PowerShell ',' is not the enumerator operator, but an array aoperator. The thing you present as multidimensional array is in fact an array of array, you'll find here under the definition of a multidimensional array :

    $a= new-object ‘object[,]’ 3,3
    $a[0,2]=3 
    PS > for ($i=0;$i -lt 3;$i++)
    >> {
    >> for($j=0;$j -lt 3;$j++)
    >> {
    >> $a[$i,$j]=$i+$j
    >> }
    >> }
    

    Everything work here as $b is an array of reference.

提交回复
热议问题