Create an array, hashtable and dictionary?

The proper way (i.e. the PowerShell way) is:

Array:

> $a = @()
> $a.gettype()

IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     True     Object[]                                 System.Array

Hashtable / Dictionary:

> $h = @{}
> $h.gettype()

IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     True     Hashtable                                System.Object

The above should suffice for most dictionary-like scenarios, but if you did explicitly want the type from Systems.Collections.Generic, you could initialise like:

> $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

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)