powershell-Basics: Arrays

Source: Internet
Author: User

(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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.