.net - PowerShell 通用集合

标签 .net powershell powershell-1.0

我一直在 PowerShell 中推进 .NET 框架,但遇到了一些我不明白的问题。这工作正常:

$foo = New-Object "System.Collections.Generic.Dictionary``2[System.String,System.String]"
$foo.Add("FOO", "BAR")
$foo

Key                                                         Value
---                                                         -----
FOO                                                         BAR

但这并没有:

$bar = New-Object "System.Collections.Generic.SortedDictionary``2[System.String,System.String]"
New-Object : Cannot find type [System.Collections.Generic.SortedDictionary`2[System.String,System.String]]: make sure t
he assembly containing this type is loaded.
At line:1 char:18
+ $bar = New-Object <<<< "System.Collections.Generic.SortedDictionary``2[System.String,System.String]"

它们都在同一个程序集中,那么我缺少什么?

正如答案中所指出的,这几乎只是 PowerShell v1 的问题。

最佳答案

在 PowerShell 2.0 中创建字典的新方法是:

$object = New-Object 'system.collections.generic.dictionary[string,int]'

关于.net - PowerShell 通用集合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/184476/

相关文章:

powershell - 邮件正文格式及修改

c# - 如何复制进程的标准输出(复制,而不是重定向)?

c# - 我如何计算使用 DateTime.Now 调用该方法的速度?

TFS 构建定义中的 Powershell 脚本

powershell - Docker 机器错误 : Hyper-V PowerShell Module is not available

powershell - 如何找到正在执行的脚本的源路径?

powershell - Copy-Item 将目录及其内容复制到 UNC 路径

c# - 枚举表单上的控件

c# - 如何修复 .NET Windows 应用程序在启动时崩溃并出现异常代码 : 0xE0434352?

c# - 从 Powershell 调用的 DLL 的当前目录错误