"Variables and Constants"
Variable: The amount that will change, temporarily storing the data so that you can call it later
Constants: Quantity that does not change
One, variable and array
"Variable", like in memory to divide a space, you can store some data, can only store a pair of
A line corresponding to an object
"Arrays", like dividing multiple storage spaces in memory, containing subscripts, can hold data from multiple objects
(1), using variable
A variable (Variable) is a memory cell in which a value is stored, and in PowerShell, the variable is represented by a single word literal string that begins with the symbol $
1, the creation and modification of variables
Format:$< variable name >=< variable value >
"The characteristics of the variable"
You do not have to declare variable types in PowerShell, you can be integers, floating-point numbers, characters, strings, arrays, and so on. For example: $sum =1; $sum =1.5; $arry = "abc", "EFG"
Variables can be created and used directly within the console
2, display the value of the variable
Enter the name of the variable in the console (beginning with $)
Use get-variable to view variables (get-variable variable names)
3, the operation of the variable
Calculate the radius of a circle
Output calculation results
"As shown above, the steps to create a variable and perform a mathematical operation"
1 Create variable $pi and assign a value of 3.1416
2) Prompts the user to enter the radius of the circle, enter a value of 12
Read-host receives user input, the stored value type is a character type (String), the numeric calculation must be converted to a numeric type, and "decimal" means that the variable is cast from character to Decimal, and decimal is a cast numeric type, representing "decimal"
3 Calculate the area of the circle with the radius of the input
The calculation formula of the circle is: area=pi* (r*r), in PowerShell, the square can be multiplied by two numbers, $r receive the user input value, the variable $area is the area of the circle, * is the multiplication operator of the PowerShell, $area = $pi * ($R * $R). () represents precedence in multiplication operations
Highest level