iTa*_*ayb 27 arrays powershell
我想在PowerShell中创建一个数组数组.
$x = @(
@(1,2,3),
@(4,5,6)
)
Run Code Online (Sandbox Code Playgroud)
它工作正常.但是,有时我在数组列表中只有一个数组.在这种情况下,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
Run Code Online (Sandbox Code Playgroud)
如何创建一个数组数组,保证它仍然是一个二维数组,即使数组中只有一个数组项?
CB.*_*CB. 46
添加逗号力以创建数组:
$x = @(
,@(1,2,3)
)
Run Code Online (Sandbox Code Playgroud)
简单方法:
$x = ,(1,2,3)
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
29463 次 |
最近记录: |