Definisce una matrice di stringhe. Considerate le seguenti modalità di inizializzazione un 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
Per default, una matrice PowerShell è un array di oggetti che sarà semplice per un tipo particolare se necessario. Guardate come si è deciso che tipo il 5 ° elemento di ciascuno di questi sono:
[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
L'uso di [string[]]
durante la creazione $s1
ha fatto sì che una cruda 3
passato alla matrice è stato convertito in un tipo String
in contrasto con un Int32
se memorizzato in un array Object
.
Tutte le tue risposte sono state fantastiche. Grazie mille ragazzi! – Cignul9