Powershell: 为什么(1)[1]与$ null不同?

创建于 2018-03-10  ·  3评论  ·  资料来源: PowerShell/PowerShell

我试图理解为什么以下两个语句产生不同的输出:

&{,$null} | % {'x'} # x
&{,(1)[1]} | % {'x'} # no output

,$null,(1)[1]似乎都是包含单个null元素的数组。 但是,它们在从脚本块输出期间的行为有所不同。 这是怎么回事

Issue-Question Resolution-Answered

所有3条评论

第二个返回AutomationNull.Value管道未枚举。

列举了$null

例如,请参见foreach的实现:
https://github.com/PowerShell/PowerShell/blob/bcf86d4f8a1ce0ef11f0e9100490e790fb067574/src/System.Management.Automation/engine/runtime/Operations/MiscOps.cs#L2748

谢谢@powercode。 对于其他读者,以下是AutomationNull一些资源:

@ alx9r :这归结为您稍后在#6436中提出的问题,我已将其集中在https://github.com/PowerShell/PowerShell/issues/6436#issuecomment -375151317中,但我已决定为此创建一个单独的问题:#6823

此页面是否有帮助?
0 / 5 - 0 等级