将数组分配给 Powershell 中的字典条目 [英] Assigning an array to a dictionary entry in Powershell
本文介绍了将数组分配给 Powershell 中的字典条目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将一个数组作为值分配给字典条目,如下所示,但它抛出异常.
I am trying to assign an array as a value to a dictionary entry as follows but its throwing exception.
$sd = New-Object 'System.Collections.Generic.SortedDictionary[int, string[]]'
$sd[0] = "Data1a", "asda";
有什么想法吗?
推荐答案
Use cast to [string[]]
:
Use cast to [string[]]
:
$sd = New-Object 'System.Collections.Generic.SortedDictionary[int, string[]]'
$sd[0] = [string[]]("Data1a", "asda")
另一个选项是将字典值类型更改为object[]
:
Another options is to change the dictionary value type to object[]
:
$sd = New-Object 'System.Collections.Generic.SortedDictionary[int, object[]]'
$sd[0] = "Data1a", "asda"
这篇关于将数组分配给 Powershell 中的字典条目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文