windows - 在 powershell 中创建一个包含字符串和列表的 HashMap ?

标签 windows powershell hashmap

在 powershell 中,如何创建包含一个字符串作为键和一个字符串列表作为值的 HashMap ?

例如,在Java中,可以做到以下几点:

Map<String, List<String> myMap = new HashMap<String, List<String>();

powershell 是否包含此功能?

我试过:

$myMap = @{ [string], New-Object Collections.Generic.List[string] } 

但这没有用。

最佳答案

$myMap = @{ "Michigan"="Detroit"; "California" = "Sacremento","Hollywood";"Texas"="Austin" } 

请注意 California 是如何为其键分配两个值的。另请注意,如果您尝试将其导出为 csv,枚举器将跳过数组值并仅将“System.Object[]”插入 csv 文件,这可能是应该的。

更新

要动态更新列表,

$myMap.California += "Compton"

关于windows - 在 powershell 中创建一个包含字符串和列表的 HashMap ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19250860/

相关文章:

python - 如何从python中的列表中删除重复的条目

kotlin - 以数组为键的 Hashmap.containsKey 不起作用

performance - 在 Rust 中,如何将快速的始终为空且单条目的 HashMap 传递给第三方 API?

windows - Chocolatey 的正确使用(包更新/版本管理)

c++ - 有没有更好的方法在 C++ 中加载 dll?

java - 加载 native 库时 OSGI 框架挂起

shell - 执行 shell 时 Jenkins 构建失败

.net - 系统在哪里存储图标位置?

powershell - 用于在管道中跨数据集循环的 Azure PowerShell 代码

powershell - 访问具有无效变量名称的管道变量属性