powershell - Returning the result of a function call with/without parentheses -


why there difference in return values of f , g in 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 understand, if function returns kind of empty collection, powershell "unwrap" null, , f expect. what's going on g?

edit: pointed out jpblanc, powershell 3.0 exhibits difference. in 2.0, both lines print null. changed?

sorry don't read correctly question, f afunction using () evaluate function. result of write-type function same me in powershell v2.0.

so, in powershell 3.0 meet problem.

now using :

trace-command -name typeconversion -expression {write-type (f)} -pshost 

versus

trace-command -name typeconversion -expression {write-type (g)} -pshost 

as far understand () before before returning object generate following

 converting "collections.generic.linkedlist" "system.type".      conversion system.type          conversion system.type              not find match "system.collections.generic.linkedlist".          not find match "collections.generic.linkedlist".  converting "collections.generic.linkedlist`1" "system.type".      conversion system.type          conversion system.type              found "system.collections.generic.linkedlist`1[t]" in loaded assemblies.  converting "object" "system.type".      conversion system.type          conversion system.type              found "system.object" in loaded assemblies. 

Comments