質問

どのように私は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」を指定しなければならないことに注意してください)。あなたは単に「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