(i) deletion and addition of elements in an array
#代表创建一个数组, containing 1 to 4 elements
PS c:\windows\system32> $num =1..4
#查看创建好的数组
PS c:\windows\system32> $num
1
2
3
4
#删除数组的第三个元素, note that is counted starting from 0, the above definition of the array has 4 elements, then the count is 0,1,2,3, so this removes the third element, is to preserve the 0,1,3 element, delete the 2nd element
PS c:\windows\system32> $num = $num [0..1]+ $num [3]
#再次查看, you can see that a third element has been deleted
PS c:\windows\system32> $num
1
2
4
#我们可以单独查看0, the element represented by 1 is
PS c:\windows\system32> $num [0..1]
1
2
#查看3代表的元素是空的, because now only 1,2,4 three numbers, the fourth element has not been, so is empty
PS c:\windows\system32> $num [3]
# $num [2] represents viewing the third element (starting from 0 is the third one) and is currently 4
PS c:\windows\system32> $num [2]
4
#添加数组中的元素, by using + =, here I add an element 3
PS c:\windows\system32> $num + = "3"
#查看结果
PS c:\windows\system32> $num
1
2
4
3
(ii) Arrays and hash tables
Arrays are used when creating a hash table because the element keywords that create arrays and hash tables do not conflict. One is a comma, the other is a semicolon.
PS c:\windows\system32> [email protected]{Name = "Xiaoming"; Age= "n"; sex= "men"; books= "Sanguo", "Suihu", "Xiyou"}
PS c:\windows\system32> $stu
name value
---- -----
Books {Sanguo, Suihu, xiyou}
name xiaoming
age 12
Sex men
PS c:\windows\system32>
This article from "Zeng Hung Xin Technical column" blog, declined to reprint!
powershell-Basics: Arrays