Search code examples
arrayspowershellpowershell-2.0notation

PowerShell: Difference between array notation?


Is there a difference between these two array creation statements? So, is '@' sign optional when creating arrays?

$a = "This", "Is", "a", "cat"
$a.GetType()
$a | gm
$a = @("This", "Is", "a", "cat")
$a.GetType()
$a | gm

Solution

  • $a = @() # declare an empty array.
    
    $a = @(mysingleitem) # declare an array with a single element
    

    In other case is optional.