Powershell array assignment assigns variable, not value?

后端 未结 2 739
遥遥无期
遥遥无期 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条回答
  •  长情又很酷
    2021-01-13 02:17

    To assign the values of $a to $b instead of the reference to $a, you can wrap the variable in $(). Anything in $() gets evaluated before using it in the command, so $($a) is equivalent to 0, 0, 0.

    $a =@(0,0,0)
    $b = @($($a),$($a),$($a))
    $b[1][2]=2
    $b
    '$a is not changed.'
    $a
    

提交回复
热议问题