PowerShell 的特殊数组 head/tail 分配记录在哪里?

Where is PowerShell's special array head/tail assignment documented?

我刚刚注意到这是有效的 PowerShell 代码:

PS> $first, $rest = @(1, 2, 3)

此语句将数组中的第一项放在 $first 中,其余项放在 $rest 中。

PS> $first
1

PS> $rest
2
3

它甚至适用于任意数量的变量,将当前头部推入下一个变量,将尾部推入最后一个变量。你可以自己试试。

PS> $first, $second, $rest = @(1, 2, 3, 4)

如果没有足够的正面或反面来放入其中一个变量,它似乎会分配一个 $null 值。即使在 $rest 的情况下(我宁愿看到一个空数组,但无论如何)。

PS> $first, $second, $rest = @(1)

PS> $first
1

PS> $second

PS> $second -eq $null
True

PS> $rest

PS> $rest -eq $null
True

PS> $rest -eq @()
False

问题和我的问题是,我没有在任何地方看到这个记录!我试图找出何时支持它。具体是如何实现的。如果它适用于任何其他类型。

我检查了 about_Assignmentabout_Arraysabout_Splatting,没有任何运气。

请参阅 about_Assignment_Operators 底部附近的以下部分...

Assigning multiple variables

In PowerShell, you can assign values to multiple variables by using a single command. The first element of the assignment value is assigned to the first variable, the second element is assigned to the second variable, the third element to the third variable, and so on. This is known as multiple assignment.