Tableaux PowerShell
De Linuxmemo.
(Différences entre les versions)
| Ligne 1 : | Ligne 1 : | ||
[[Catégorie:PowerShell]] | [[Catégorie:PowerShell]] | ||
| - | + | ==Déclaration (d'un tableau vide)== | |
$NomTableau = @() | $NomTableau = @() | ||
ou avec tun typage | ou avec tun typage | ||
| Ligne 8 : | Ligne 8 : | ||
ou | ou | ||
$tab = 1,5,9,10,6 | $tab = 1,5,9,10,6 | ||
| + | ==Lecture d'un tableau== | ||
| + | $tab[0] | ||
| + | $tab[0,2] | ||
| + | $tab[1..20 | ||
| + | |||
| + | *Dernier indice | ||
| + | $tab[$tab.length-1] | ||
| + | ou | ||
| + | $tab[-1] | ||
| + | Quand on utilise un indice négatif, on fait référence depuis la fin du tableau. | ||
Version du 23 février 2017 à 15:07
Déclaration (d'un tableau vide)
$NomTableau = @()
ou avec tun typage
[String[]]$NomTableau = @()
Déclaration avec initialisation en même temps
$tab = @(1,5,9,10,6) ou $tab = 1,5,9,10,6
Lecture d'un tableau
$tab[0] $tab[0,2] $tab[1..20
- Dernier indice
$tab[$tab.length-1] ou $tab[-1]
Quand on utilise un indice négatif, on fait référence depuis la fin du tableau.