PowerShell的特殊数组头/尾分配在哪里记录? [英] Where is PowerShell's special array head/tail assignment documented?

查看:58
本文介绍了PowerShell的特殊数组头/尾分配在哪里记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I only just noticed that this is valid PowerShell code:

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

此语句将第一个项目放入在 $ first 中的数组和在 $ rest 中的其余项。

This statement puts the first item in the array in $first and the remaining items in $rest.

PS> $first
1

PS> $rest
2
3

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

It even works for an arbitrary number of variables, pushing the current head into the next variable and the tail into the last one. You can try that for yourself.

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

如果没有足够的开头或结尾放入变量之一,则分配 $ null 值。即使在 $ rest 的情况下(我宁愿看到一个空数组,但无论如何)。

It seems to assign a $null value if there aren't enough heads or tails to put into one of the variables. Even in the case of the $rest (I'd rather have seen an empty array, but whatever).

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

问题和我的问题是我在任何地方都看不到此文件!我正在尝试找出何时支持。确切的实施方式。如果它适用于任何其他类型。

The problem, and my question, is that I don't see this documented anywhere! I'm trying to find out when this was supported. Exactly how it's implemented. If it works for any other types.

我检查了 about_Assignment about_Arrays about_Splatting ,没有任何运气。

I checked about_Assignment, about_Arrays, and about_Splatting, without any luck.

推荐答案

请参阅底部附近的分配多个变量部分。 about_Assignment_Operators

See the section ASSIGNING MULTIPLE VARIABLES near the bottom of about_Assignment_Operators.

这篇关于PowerShell的特殊数组头/尾分配在哪里记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆