更新时间:2023-11-08 12:54:04
另一个选择:
为($ I = 0; $ I -lt 5; $ I ++)
{
$ ARR + = @($ FALSE)
}
如果$ ARR还没有定义这一件作品。
What's the best way to initialize an array in PowerShell?
For example, the code
$array = @()
for($i=0; $i -lt 5;$i++)
{
$array[$i] = $FALSE
}
generates the error
Array assignment failed because index '0' was out of range.
At H:\Software\PowerShell\TestArray.ps1:4 char:10
+ $array[$ <<<< i] = $FALSE
Yet another alternative:
for ($i = 0; $i -lt 5; $i++)
{
$arr += @($false)
}
This one works if $arr isn't defined yet.