Array.Add vs +=

前端 未结 3 2072
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-29 19:33

I\'ve found some interesting behaviour in PowerShell Arrays, namely, if I declare an array as:

$array = @()

And then try to add items to it

3条回答
  •  庸人自扰
    2020-11-29 20:02

    The most common idiom for creating an array without using the inefficient += is something like this, from the output of a loop:

    $array = foreach($i in 1..10) { 
      $i
    }
    $array
    

提交回复
热议问题