如何创建PowerShell中的数组的数组? [英] How to create array of arrays in powershell?
本文介绍了如何创建PowerShell中的数组的数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要创建数组的PowerShell中的数组。
I want to create an array of arrays in powershell.
$x = @(
@(1,2,3),
@(4,5,6)
)
正常工作。但是,有时我在数组列表只有一个阵列。在这种情况下,的powershell忽略列表之一:
Works fine. However, sometimes I have only one array in the array list. In that situation, powershell ignores one of the lists:
$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
如何创建一个数组的数组,保证它继续作为一个两维数组,即使该数组中有只有一个数组项?
How do I create an array of arrays, guaranteed it's remain as a two-dimension array even if the array has only one array item in it?
推荐答案
添加一个逗号力来创建一个数组:
Adding a comma force to create an array:
$x = @(
,@(1,2,3)
)
简单的方法:
$x = ,(1,2,3)
这篇关于如何创建PowerShell中的数组的数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文