Documente Academic
Documente Profesional
Documente Cultură
about_Arithmetic_Operators
DESCRIPTION COURTE
DESCRIPTION LONGUE
suivants :
-4
de fois spécifié.
l'ordre suivant :
Parenthèses ()
*, /, %
+, - (pour la soustraction)
11
C:\PS> 10+4/2
12
C:\PS> (10+4)/2
C:\PS> $a = 0
C:\PS> $b = 1,2
C:\PS> $c = -1,-2
C:\PS> $b
-1
Vous pouvez ajouter des nombres, des chaînes, des tableaux et des
les ajoutent :
C:\PS> $a = 1,2,3
C:\PS> $b = "A","B,"C"
C:\PS> $a + $b
C
Vous pouvez également exécuter des opérations arithmétiques sur
C:\PS> "fichier" + 16
fichier16
C:\PS> $array + 16
16
fichier
C:\PS> "fichier" * 3
fichierfichierfichier
Étant donné que la méthode utilisée pour évaluer les instructions est
C:\PS> "fichier" + 2
fichier2
C:\PS> 2 + "fichier"
incorrect. "
À la ligne : 1 Caractère : 4
+ 2 + <<<< "fichier"
C:\PS> "fichier" * 3
fichierfichierfichier
C:\PS> 3 * "fichier"
incorrect. "
À la ligne : 1 Caractère : 4
+ 3 * <<<< "fichier"
Les tables de hachage représentent un cas légèrement différent.
Name Value
---- -----
c2 Server02
a 1
b 2
c1 Server01
c 3
C:\PS> $hash1 + 2
table de hachage.
À la ligne : 1 Caractère : 9
+ $hash1 + <<<< 2
C:\PS> 2 + $hash1
À la ligne : 1 Caractère : 4
+ 2 + <<<< $hash1
Name Value
---- -----
a 1
b 2
c 3
C:\PS> $sum.count
C:\PS> $sum[3]
Name Value
---- -----
a 1
b 2
c 3
Name Value
---- -----
a 1
b 2
c 3
c2 Server02
L'exemple suivant montre que vous ne pouvez pas ajouter les unes
été ajouté. Clé du dictionnaire : " c " Clé ajoutée : " c ".
À la ligne : 1 Caractère : 9
C:\PS> $array
fichier
C:\PS> $array
C:\PS> $array
fichier
C:\PS> $hash1
Name Value
---- -----
a 1
b 2
c 3
C:\PS> $hash1
Name Value
---- -----
a 1
b 2
e 5
c 3
C:\PS> 2 + 3.1
5.1
System.Int32
C:\PS> (2 + 3.1).GetType().FullName
System.Double
l'exemple suivant :
C:\PS> (512MB).GetType().FullName
System.Int32
System.Double
non signé et l'entier non signé est trop grand pour être converti
en Int32 :
System.Int64
Dans cet exemple, Int64 peut prendre en charge les deux types.
C:\PS> [Decimal]::maxvalue
79228162514264337593543950335
C:\PS> [Decimal]::maxvalue + 1
À la ligne : 1 Caractère : 22
+ [Decimal]::maxvalue + <<<< 1
OPÉRATEURS ARITHMÉTIQUES ET VARIABLES
C:\PS> $intA = 6
C:\PS> $intB = 4
10
C:\PS> $c = 2
C:\PS> $a + $b + $c
Windows PowerShell 2
PowerShell :
C:\PS> get-date
EXEMPLES
C:\PS> 1 + 1
C:\PS> 1 - 1
0
C:\PS> -(6 + 3)
-9
C:\PS> 6 * 2
12
C:\PS> 7 / 2
3.5
C:\PS> 7 % 2
C:\PS> w * 3
www
C:\PS> 3 * "w"
À la ligne : 1 Caractère : 4
+ 3 * <<<< "w"
Windows PowerShell
PS C:\ps-test> $a
Windows PowerShell
C:\PS> $a[0]
W
C:\PS> $a = "FichiersTest.txt"
C:\PS> $b = "C:\Logs\"
C:\PS> $b + $a
C:\Logs\FichiersTest.txt
C:\PS> $a = 1,2,3
C:\PS> $a + 4
Name Value
---- -----
3 Server03
2 Server02
1 Server01
0 LocalHost
C:\PS> $servers
Name Value
---- -----
2 Server02
1 Server01
0 LocalHost
C:\PS> $servers
Name Value
---- -----
3 Server03
2 Server02
1 Server01
0 LocalHost
VOIR AUSSI
about_Arrays
about_Assignment_Operators
about_Comparison_Operators
about_Hash_Tables
about_Operators
about_Variables
Get-Date