It defines an array of strings. Consider the following ways to initialize an array:
[PS] > [string[]]$s1 = "foo","bar","one","two",3,4 [PS] > $s2 = "foo","bar","one","two",3,4 [PS] > $s1.gettype() IsPublic IsSerial Name BaseType -------- -------- ---- -------- True True String[] System.Array [PS] > $s2.gettype() IsPublic IsSerial Name BaseType -------- -------- ---- -------- True True Object[] System.Array
By default, the powershell array is an array of objects that will be passed to a particular type if necessary. See how he determined what types the 5th element of each will be:
[PS] > $s1[4].gettype() IsPublic IsSerial Name BaseType -------- -------- ---- -------- True True String System.Object [PS] > $s2[4].gettype() IsPublic IsSerial Name BaseType -------- -------- ---- -------- True True Int32 System.ValueType [PS] > $s1[4] 3 [PS] > $s2[4] 3
Using [string[]] when creating $s1 meant that raw 3 passed to the array was converted to a String type, unlike Int32 if it was stored in an Object array.
source share