Reputation: 55
In Powershell I need to pass an input to a method of type System.Collections.Generic.IDictionary[string, system.object].
Could someone please help me with a sample code on how IDictionary[string,system.object] could be declared and value is set to it.
Upvotes: 2
Views: 6472
Reputation: 3414
Another way to that given in Andrey Marcheuk's answer.
$dict = [System.Collections.Generic.Dictionary[string,object]]::new()
A less expressive way but quite concise is an empty hashtable.
$dict = @{}
From which follows a way to set up data.
$dict = @{"badger"="Mustelidae"; "tiger"="Panthera"; "snake"="Serpentes"}
A single value can be added or updated.
$dict.badger = "Mustelidae"
Upvotes: 3
Reputation: 13483
Something like:
$dict = New-Object 'system.collections.generic.dictionary[[string],[object]]
Upvotes: 2