Why is there a difference in the return values of F and G in the following code?
Function F {
Return (New-Object Collections.Generic.LinkedList[Object])
}
Function G {
Return New-Object Collections.Generic.LinkedList[Object]
}
Function Write-Type($x) {
If($null -eq $x) {
Write-Host "null"
} Else {
Write-Host $x.GetType()
}
}
Write-Type (F) # -> null
Write-Type (G) # -> System.Collections.Generic.LinkedList`1[System.Object]
As far as I understand, if a function returns some kind of empty collection, PowerShell will "unwrap" it into null, and so F does what I expect. But what's going on with G?
Edit: As pointed out by JPBlanc, only PowerShell 3.0 exhibits this difference. In 2.0, both lines print null
. What changed?