【发布时间】:2012-06-23 16:41:17
【问题描述】:
我想在 PowerShell 中创建一个数组数组。
$x = @(
@(1,2,3),
@(4,5,6)
)
它工作正常。但是,有时我在数组列表中只有一个数组。在这种情况下,PowerShell 会忽略以下列表之一:
$x = @(
@(1,2,3)
)
$x[0][0] # Should return 1
Unable to index into an object of type System.Int32.
At line:1 char:7
+ $a[0][ <<<< 0]
+ CategoryInfo : InvalidOperation: (0:Int32) [], RuntimeException
+ FullyQualifiedErrorId : CannotIndex
如何创建一个数组数组,即使数组中只有一个数组项,也能保证它保持为二维数组?
【问题讨论】:
-
注意:在使用数组数组的地方,逗号的位置似乎也很重要。更多信息:windowsserver.uservoice.com/forums/301869-powershell/…
标签: arrays powershell