我一直在 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/