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

2024-01-04

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

$sd = New-Object 'System.Collections.Generic.SortedDictionary[int, string[]]'
$sd[0] = "Data1a", "asda";

任何想法?


使用强制转换为[string[]]:

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

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

$sd = New-Object 'System.Collections.Generic.SortedDictionary[int, object[]]'
$sd[0] = "Data1a", "asda"
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

在 Powershell 中将数组分配给字典条目 的相关文章

随机推荐