PowerShell array of arrays:
[string[][]] $array = @(
,@('one', 'two')
,@('three', 'four')
)
$array.ForEach({$_.GetType().Name, $_.Length, ($_ -join '-')})
结果符合预期:
String[] # first item is a string array
2 # has 2 elements
one-two # one and two
String[] # second item is a string array
2 # has 2 elements
three-four# three and four
但是,如果我们不使用换行符将数组分开:
[string[][]] $array = @(
,@('one', 'two'), @('three', 'four')
)
输出变为:
String[] # there are still 2 arrays
1 # but the first one has now only 1 element
one two # the two expected elements got concatenated into 1
String[] # second array is ok
2
three-four
那是为什么?
PSVersion 5.1.18298.1000