为什么换行会更改PowerShell多维数组创建中的语义?

时间:2018-12-21 19:00:32

标签: powershell powershell-v5.0

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

0 个答案:

没有答案