Ответ 1
Правильный способ (т.е. способ PowerShell):
Массив:
> $a = @()
> $a.gettype()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True Object[] System.Array
Hashtable/Словарь:
> $h = @{}
> $h.gettype()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True Hashtable System.Object
Вышеупомянутое должно быть достаточным для большинства сценариев, подобных словарю, но если вы явно хотите тип из Systems.Collections.Generic
, вы можете инициализировать, например:
> $d = New-Object 'system.collections.generic.dictionary[string,string]'
> $d.gettype()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True Dictionary`2 System.Object
> $d["foo"] = "bar"
> $d | Format-Table -auto
Key Value
--- -----
foo bar