, Comma operator
As a binary operator, the comma creates an array. As a unary
operator, the comma creates an array with one member. Place the
comma before the member.
Source. https://technet.microsoft.com/en-us/library/hh847732.aspx
这是因为@('a','b')
将推动两根弦a
and b
进入数组$b
而你强迫@('c','d')
被推入$b
as an array
使用逗号。
Example:
$b = @( @('a','b')
, @('c','d'))
$b | foreach { Write-Host "Item: $_"}
Output:
Item: a
Item: b
Item: c d
如果你看一下类型:
$b | foreach { $_.GetType()}
You get:
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True String System.Object
True True String System.Object
True True Object[] System.Array
强迫$b
包含两个arrays
,使用逗号二元运算符:
$b = @(@('a','b'),@('c','d'))