我试图理解为什么以下两个语句产生不同的输出:
&{,$null} | % {'x'} # x
&{,(1)[1]} | % {'x'} # no output
,$null
和,(1)[1]
似乎都是包含单个null元素的数组。 但是,它们在从脚本块输出期间的行为有所不同。 这是怎么回事
第二个返回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