Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在PowerShell中创建新System.Collections.Generic.Dictionary对象失败_Powershell - Fatal编程技术网

在PowerShell中创建新System.Collections.Generic.Dictionary对象失败

在PowerShell中创建新System.Collections.Generic.Dictionary对象失败,powershell,Powershell,PowerShell版本:5.x,6 我正在尝试创建System.Collections.Generic.Dictionary的新对象,但失败了 我尝试了以下“版本”: 我知道我可以在PowerShell下使用哈希表,但我想知道如何通过上述声明创建字典 我错过了什么 Thx问题在于你如何解释你的论点 当您在字符串中包含逗号时,它现在正试图绑定 'System.Collections.Generic.Dictionary[[string]', '[int]]' 指向类型为的-TypeName参数

PowerShell版本:5.x,6

我正在尝试创建
System.Collections.Generic.Dictionary
的新对象,但失败了

我尝试了以下“版本”:

我知道我可以在PowerShell下使用哈希表,但我想知道如何通过上述声明创建字典

我错过了什么

Thx

问题在于你如何解释你的论点

当您在字符串中包含逗号时,它现在正试图绑定

'System.Collections.Generic.Dictionary[[string]', '[int]]'
指向类型为
-TypeName
参数或错误消息中的
。这可以通过正确引用您的参数来解决,使其与
的预期参数绑定相匹配:


使用的类型名称
System.Collections.Generic.Dictionary[[string],[int]]
包含逗号。作者:

要创建和初始化数组,请为数组指定多个值 变量存储在数组中的值用分隔符分隔 逗号

因此,您需要转义逗号(阅读和帮助主题)。还有更多选择:

在Windows PowerShell中,转义字符是反勾号(
`
), 也称为严重口音(ASCII 96)

引号用于指定文字字符串。你可以附上 单引号(
)或双引号中的字符串 (


使用“
新对象系统.集合.泛型.词典[[string]`,[int]]]
”作为“
新对象”系统.集合.泛型.词典[[string],[int]]”作为“
新对象系统.集合.泛型.词典[[string],[int]]”来转义逗号。它有效。请添加您的注释作为答案。
'System.Collections.Generic.Dictionary[[string]', '[int]]'
New-Object -TypeName 'System.Collections.Generic.Dictionary[[string], [int]]'
$dictionary = new-object System.Collections.Generic.Dictionary[[string]`,[int]]
$dictionary = new-object "System.Collections.Generic.Dictionary[[string],[int]]"
$dictionary = new-object 'System.Collections.Generic.Dictionary[[string],[int]]'