February 2019
Intermediate to advanced
626 pages
15h 51m
English
Individual elements may be selected by a key. As with the hashtable, two different notations are supported:
$dictionary["Computer1"] # Key reference $dictionary.Computer1 # Dot-notation
We've seen that, when adding elements, types are converted. Looking back to selecting elements from a hashtable, we know that the value for the key was sensitive to type. As the dictionary has a type declared for the key, it can leverage PowerShell's type conversion.
Consider a dictionary created using a number as a string for the key:
$dictionary = New-Object System.Collections.Generic.Dictionary"[String,IPAddress]"
$dictionary.Add("1", "192.168.10.222")
$dictionary.Add("2", "192.168.10.13")
Each of the following examples ...
Read now
Unlock full access