4 ms·
ArrayList.Add ... whatever ... | Out-Null Its not implicitly returning. The return value wasn't assigned so it is emitted to the pipeline.
by new_hackers 10y ago
ArrayList.Add ... whatever ... | Out-Null
Its not implicitly returning. The return value wasn't assigned so it is emitted to the pipeline.
- emodendroket 10y agoOK, sorry (there is an explicit "return" keyword that I thought worked the same way). Either way, yes, I know you can avoid it by piping to Out-Null, but that behavior is surprising.
- ygra 10y agoreturn {expression} is equivalent to {expression} return the only place you have an exit from a function, script block or similar is either at the end or at a return statement. Every value that isn't assigned or piped into nirvana gets pushed to the pipeline. I actually can't remember having used return statements more often than once or twice so far (and I use PowerShell daily, heavily). Then I rarely found the need to use ArrayList. Sure, you can use it, but you can just as well do $array = @() $array += $item A personal pet peeve of mine is actually that lots of people write PowerShell very similar to equivalent VBScript or C# code. And that makes for horrible PowerShell code (in my eyes). The pipeline is immensely powerful and not using it often makes for pretty crappy code.
- emodendroket 10y agoMost people writing PowerShell scripts are likely dabblers though. Anyway, I have to admit I don't really appreciate the whole pipeline idea; I just know that `$something = Some-Function` sometimes wouldn't do what I thought it would because of these semantics.