Curious, what is the idea behind this:
@() -as [bool]
# False
@($null) -as [bool]
# False
@($null, $null) -as [bool]
# True
I would expect either False/True/True or False/False/False, but not False/False/True.
Curious, what is the idea behind this:
@() -as [bool]
# False
@($null) -as [bool]
# False
@($null, $null) -as [bool]
# True
I would expect either False/True/True or False/False/False, but not False/False/True.
As outlined in the Powershell Quick reference¹:
True False ~~~~ ~~~~~ $TRUE $FALSE Any string of length > 0, except the word “false” Empty string or the string “false” Any number ≠ 0 Any number = 0 Array of length > 1 Array of length 0 Array of length 1 whose element is true Array of length 1 whose element is false A reference to any object Null
I think the idea behind it was that an array with just one element $false
can easily happen if you put the output of a cmdlet/function into an array. You might expect more values but some error made it to return $false
, but $false
twice in the array might be unlikely in that case.
Or maybe we should wait for Jeffrey Snover to answer here :-)
¹ C:\Windows\System32\WindowsPowerShell\v1.0\Documents\en-US\QuadFold.rtf on my machine