Simple demonstration
In order to demonstrate the array subexpression operator, three
functions are created.
func_0
returns
nothing,
func_1
returns a scalar («one element») and
func_n
returns more than one element (here: 3)
function func_0 { }
function func_1 { 'one element ' }
function func_n { 'foo', 'bar', 'baz' }
The following snippet embeds these functions into the array subexpression operator and creates three arrays whose number of elements correspond to the number of elements that are returned by the embedded function:
$ary_0 = @( func_0 )
$ary_1 = @( func_1 )
$ary_n = @( func_n )
$ary_0.GetType().FullName # System.Object[]
$ary_1.GetType().FullName # System.Object[]
$ary_n.GetType().FullName # System.Object[]
$ary_0.length # 0
$ary_1.length # 1
$ary_n.length # 3