Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays 如何在PowerShell中创建阵列阵列?_Arrays_Powershell - Fatal编程技术网

Arrays 如何在PowerShell中创建阵列阵列?

Arrays 如何在PowerShell中创建阵列阵列?,arrays,powershell,Arrays,Powershell,我想在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][ <<&

我想在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
$x=@(
@(1,2,3)
)
$x[0][0]#应返回1
无法索引到System.Int32类型的对象。
第1行字符:7

+$a[0][添加逗号强制以创建数组:

$x = @(
    ,@(1,2,3)
)
简单方法:

$x = ,(1,2,3)

神奇的逗号又来了!为什么powershell不会创建没有逗号的数组?这是一篇关于魔法的好文章:。逗号运算符当然是powershell中的数组构造运算符,那么为了语法的一致性,您希望这
@(,@(1,2,3),@(4,5,6))
可以……但它没有给你你想要的。叹气。微软破坏了上面评论中的链接。新位置是NB:在这里,使用数组数组似乎逗号的位置也很重要。更多信息如下: