What is the difference between @() and @{} in Powershell and when to use one over another?

Question:

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!

Answer:

An array is simply a list of values whereas a hashtable is a collection of key/value pairs.

Here are some examples:

Array

Hashtable

Source:

What is the difference between @() and @{} in Powershell and when to use one over another? by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply