Stady notes: Windows powershell tips -Even More Things You Can Do With Arrays

来源:互联网 发布:云计算开源平台 编辑:程序博客网 时间:2024/05/16 06:00

1.定义一个空的数组

$a = @()              # 这样定义是不行的 [array]$a,奇怪的语法啊。

或者用。net framwork 里面的 $a = new-object System.collection.arrayList

 

2.定义一个固定类型的空数组

[int[]]$a = @()

 

3,定义一个已知元素的数组

$a = "one","two","three","four"

$a = 1,2,3,4

$a = 1..100

 

4.添加元素到数组

比如,添加4,就是$a = $a +4,添加元素用 “+”

$a = $a + (get-date)

 

5.combining two or more arrays

$a = 'red',"white","blue"

$b = "green","orange","yellow"

$c = $a + $b