Today I noticed an interested behavior of PowerShell and I made the following code to show it. When you run:
function test()
{
$a = @(1,2);
Write-Host $a.gettype()
return $a;
}
$b = test
Write-Host $b.gettype();
What you got is:
System.Object[]
System.Object[]
However when you change the code to:
function test()
{
$a = @(1);
Write-Host $a.gettype()
return $a;
}
$b = test
Write-Host $b.gettype();
You will got:
System.Object[]
System.Int32
Can someone provide some more details on this "feature"? Seems the PowerShell specification did not mention this.
Thanks.
BTW, I tested the code on PowerShell version 2, 3 & 4.