Suppose I have a couple of arrays:
$a = 1,2,3
$b = 4,5,6
and I get the intersection (empty):
$c = $a |?{$b -contains $_}
I would expect $c to contain an empty list such that I could do:
$c.length
but I don't. I get a $null (which issues an exception when queried for .length). How can I get an empty list back instead?
Wrap it in the array constructor:
$c = @($a | ? { $b -contains $_ })
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With