I was going through some examples in powershell and see the usage of both @()
and @{}
. Doing a quick google search on the difference tells me that one is an array and another is hashtable.
Could you share some real-life examples where say I would like to build a hashtable and not an array? And pros/cons of one over another? Thanks in advance for your inputs!
An array is simply a list of values whereas a hashtable is a collection of key/value pairs.
Here are some examples:
$i = @(1,2,3,4,5)
[hashtable]$i = @{ Number = 1; Shape = "Square"; Color = "Blue"}