将数组分配给Powershell中的字典条目

nab*_*rid 4 powershell powershell-2.0

我试图将一个数组作为值分配给字典条目,如下所示,但它抛出异常.

$sd = New-Object 'System.Collections.Generic.SortedDictionary[int, string[]]'
$sd[0] = "Data1a", "asda";
Run Code Online (Sandbox Code Playgroud)

任何的想法?

Rom*_*min 7

使用演员[string[]]:

$sd = New-Object 'System.Collections.Generic.SortedDictionary[int, string[]]'
$sd[0] = [string[]]("Data1a", "asda")
Run Code Online (Sandbox Code Playgroud)

另一个选项是将字典值类型更改为object[]:

$sd = New-Object 'System.Collections.Generic.SortedDictionary[int, object[]]'
$sd[0] = "Data1a", "asda"
Run Code Online (Sandbox Code Playgroud)