我怎么会做在PowerShell中2列表? 我已经试过这:点击

[activator]::createinstance(([type]'system.collections.generic.list`1').makegenerictype([string]))

和结果

[activator]::createinstance(([type]'system.collections.generic.list`1').makegenerictype([string]))

和我得到的只是什么都没有。这是怎么回事了?

我运行XP SP3,如果它的事项

有帮助吗?

解决方案

尝试这种情况:

PS> $list = New-Object 'System.Collections.Generic.List[string]'
PS> $list.Add('foo')
PS> $list
foo

PS> $d = New-Object 'System.Collections.Generic.Dictionary[string,datetime]'
PS> $d.Add('moonshot', [datetime]'7/20/1969')
PS> $d['moonshot']

Sunday, July 20, 1969 12:00:00 AM

其他提示

如果您尝试创建基于字符串列表,试试这个:

New-Object 'System.Collections.Generic.List[system.string]'

请注意,你必须指定“system.string”(至少在我的补偿;))。如果你只是使用“串”,它抛出一个异常。

[61]: New-Object 'System.Collections.Generic.List[string]'
New-Object : Cannot find type [System.Collections.Generic.List[string]]: make sure the assembly containing this type is loaded.
At line:1 char:11
+ New-Object <<<<  'System.Collections.Generic.List`1[string]'
    + CategoryInfo          : InvalidType: (:) [New-Object], PSArgumentException
    + FullyQualifiedErrorId : TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top